Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Win32::GUI: how to find BrowseForFolder()'s handle?

by Anonymous Monk
on Sep 21, 2012 at 06:35 UTC ( [id://994821]=note: print w/replies, xml ) Need Help??


in reply to Win32::GUI: how to find BrowseForFolder()'s handle?

My question is: how to make BrowseForFolder() come to the foreground?

I have a sneaking suspicion that you simply don't :) I read about it a long time ago on MSDN and I don't recall the details very well :| you might search if you're interested, but I find MFC/Win32 very tiresome :)

But basically you can only ask the desktop to raise the window, but you can't force it, you can't steal the focus / force it upon a user -- users don't like surprises (all of a sudden you're typing a letter and BLAMMO, you're selecting OK on some evil button)

Code example:

I can tell just by looking that doesn't compile

  • Comment on Re: Win32::GUI: how to find BrowseForFolder()'s handle?

Replies are listed 'Best First'.
Re^2: Win32::GUI: how to find BrowseForFolder()'s handle?
by HelenCr (Monk) on Sep 21, 2012 at 10:05 UTC
    But basically you can only ask the desktop to raise the window, but you can't force it,

    Not correct. Like I said in the OP, GetOpenFileName() and GetSaveFileName(), for example, pop up and show at the foreground, on top of all other existing windows. So why should BrowseForFolder() be different? It's the same type of window/interaction.

    I can tell just by looking that doesn't compile

    Not correct. That code compiles fine.

      Not correct.

      How do you know?

      Like I said in the OP, GetOpenFileName() and GetSaveFileName(), for example, pop up and show at the foreground, on top of all other existing windows. So why should BrowseForFolder() be different? It's the same type of window/interaction.

      It isn't. Neither one will pop up if they (the parent, the app) don't have focus (aka permission ) to pop up -- they simply flash on the taskbar

      Not correct. That code compiles fine.

      Oh really?

      $ perl $InputDir = Win32::GUI::BrowseForFolder( -root => $TopDir, -includefil +es => 1, -title => 'Select directory fo +r parameter file', -text =>'text Selext directory + for parameter file', -size => [50/100*$dw, 50/100*$ +dh], -addexstyle => WS_EX_TOPMOST,); ^Z Undefined subroutine &Win32::GUI::BrowseForFolder called at - line 1.

      Really?

      use Win32::GUI; use warnings; $InputDir = Win32::GUI::BrowseForFolder( -root => $TopDir, -includefil +es => 1, -title => 'Select directory fo +r parameter file', -text =>'text Selext directory + for parameter file', -size => [50/100*$dw, 50/100*$ +dh], -addexstyle => WS_EX_TOPMOST,); __END__ Name "main::dh" used only once: possible typo at - line 6. Name "main::InputDir" used only once: possible typo at - line 3. Name "main::dw" used only once: possible typo at - line 6. Name "main::TopDir" used only once: possible typo at - line 3. Use of uninitialized value $dw in multiplication (*) at - line 3. Use of uninitialized value $dh in multiplication (*) at - line 3. Use of uninitialized value in subroutine entry at - line 3.

      How do I post a question effectively? , Basic debugging checklist , How (Not) To Ask A Question

        The code piece was just a code snippet, to illustrate the problem. Obviously in the OP it was not intended as a complete program. (See new code example below).

        To recall the two problems:

        1. The "BrowseForFolder()" window does not show up at the foreground, while all other windows do. This is disturbing and annoying, and can lead to many problems.

        Here is a complete (compileable and running) code example. (5.014 is not essential)

        use strict; use warnings; use 5.014; use Win32::GUI(); use Win32::GUI qw{ WS_EX_TOPMOST}; my ($InputDir, $TopDir, $InputFileName, $dw, $dh, $desktop, $Window); $TopDir = 'D:\My documents'; # Change this to an existing direcotry + of yours $desktop = Win32::GUI::GetDesktopWindow(); $dw = Win32::GUI::Width($desktop); $dh = Win32::GUI::Height($desktop); $Window = Win32::GUI::Window->new( -name => 'main', -text => 'Main win +dow', -pos => [20/100*$dw, 20/100*$dh], -size => [50/100*$dw, 60/100 +*$dh], -onTerminate => \&TerminateWindow, -addexstyle => WS_EX_TOPMOST, -dialogui => 1, -tabstop => 1 +, -cancel => 1, ); $Window -> AddButton ( -name => 'ButtonCommit', -pos => [10,10], -size =>[16/100*$dw,3.5/100*$dh], -text => 'Commit changes', -onCl +ick => \&Commit); sub Commit { $InputDir = Win32::GUI::BrowseForFolder( -root => $TopDir, -includefil +es => 1, -title => 'Select directory for parameter file', -text =>'Selext directory for parameter file', -size => [50/100*$dw, 50/100*$dh], -addexstyle => +WS_EX_TOPMOST,); $InputFileName = Win32::GUI::GetOpenFileName( -title => 'Select the i +nput file', -directory => $InputDir, -file => "\0" . " " x 256, -filter => ["Text files (*.txt)" => "*.txt", "All files", "*.* +", ], -text => 'text Select input file'); } # end sub Commit $Window ->Show(); Win32::GUI::Dialog(); sub TerminateWindow { return -1; }

        Click the "Commit changes" button, then minimize the main window. Note that the "BrowseForFolder()" window hides behind other windows, and you need to minimize other windows to get to it. All other Perl Win32::GUI windows do open up at the foreground. Furthermore, note that -addexstyle => WS_EX_TOPMOST doesn't have an effect, while it usually does in Perl Win32::GUI windows.

        Note: change the 'D:\My documents' to an existing directory of yours.

        2. How does one find the desktop windows handles? If we could find BrowseForFolder()'s handle, we could raise it to the foreground (how?)

        Many TIA

        Helen

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://994821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-20 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found