in reply to Win32::FileOp window positioning?

Please check if id() returns a decimal or hexadecimal value (it may be the latter) and convert if necessary.

Replies are listed 'Best First'.
Re: Re: Win32::FileOp window positioning?
by spikey_wan (Scribe) on Mar 19, 2004 at 14:35 UTC
    Aha, thanks eserte! Now I'm really getting somewhere!! I converted the window id from hex to dec, and it worked for OpenDialog and SaveAsDialog, but it doesn't work for BrowseForFolder.

    Here's an almost completely working snippet, except that I still can't position the BrowseForFolder dialog.

    use strict; use warnings; use Tk; use Win32::FileOp; my $mw = MainWindow -> new; $mw -> withdraw; my $windowid = hex ($mw -> id); my $openbutton = $mw -> Button ( -text => 'Open', -command => \&opensub, ) -> pack; my $savebutton = $mw -> Button ( -text => 'save', -command => \&savesub, ) -> pack; my $browsebutton = $mw -> Button ( -text => 'browse', -command => \&browsesub, ) -> pack; $mw -> Popup; MainLoop; sub opensub { my $file = OpenDialog(-title => "open", -handle => $windowid); } sub savesub { my $file = SaveAsDialog(-title => "save", -handle => $windowid); } sub browsesub { my $dir = BrowseForFolder ("no handle"); my $dir1 = BrowseForFolder("with handle", -handle => $windowid); }

      BrowseForFolder() doesn't (yet) support this style of calling. And there aparently was a bug in the code. Could you try to replace the BrowseForFolder in FileOp.pm with the following code:

      sub BrowseForFolder { undef $Win32::FileOp::Error; my $lpszTitle = shift() || "\0"; my $nFolder = shift() || 0; my $ulFlags= (shift() || 0) | 0x0000; my $hwndOwner = (defined $_[0] ? shift() : GetWindowHandle()); my ($pidlRoot, $pszDisplayName, $lpfn, $lParam, $iImage, $pszPath) = ("\0"x260, "\0"x260, 0, 0, 0, "\0"x260 ); $nFolder = CSIDL_DRIVES() unless defined $nFolder; $Win32::FileOp::SHGetSpecialFolderLocation->Call($hwndOwner, $nFold +er, $pidlRoot) and return undef; $pidlRoot = hex unpack 'H*',(join'', reverse split//, $pidlRoot); my $browseinfo = pack 'LLppILLI', ($hwndOwner, $pidlRoot, $pszDisplayName, $lpszTitle, $ulFlags, $lpfn, $lParam, $iImage); my $bool = $Win32::FileOp::SHGetPathFromIDList->Call( $Win32::FileOp::SHBrowseForFolder->Call($browseinfo), $pszPath ); $pszPath =~ s/\0.*$//s; $bool ? $pszPath : undef; }
      and then use
      my $dir1 = BrowseForFolder("with handle", undef, undef, $windowid);

      I have a few more changes pending to be released, hopefully I'll have some spare time to do that sometime soon.

      HTH, Jenda
      We'd like to help you learn to help yourself
      Look around you, all you see are sympathetic eyes
      Stroll around the grounds until you feel at home
         -- P. Simon in Mrs. Robinson

        Hi Jenda,

        Thanks for the work you're doing on this, it's greatly appreciated. Let me know if I can do anything to help.

        I have tried the above, and it did work.

        There is one slight anomaly: The Browse window appears slightly lower and more to the right than the Open and Save windows do.

        Thanks again,
        Spike.