richz has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I would like to bring the command shell that was used to start a perl script into the foreground. I'd appreciate any input on how to do this. I figure there is probably a module out there to do this or at least some way of getting the handle to the window. As I stated in the subject I'm asking about Win32.

Thanks.

Update: Please read my followup reply. Thanks.
  • Comment on Bring Win32 command window to foreground

Replies are listed 'Best First'.
Re: Bring Win32 command window to foreground
by skx (Parson) on Oct 11, 2004 at 20:42 UTC

    One way to do this is to use Win32::API::Prototype, as follows:

    use Win32::API::Prototype; ApiLink( 'kernel32.dll', 'HWND GetConsoleWindow()' ) || die; ApiLink( 'user32.dll', 'BOOL ShowWindow( HWND hWnd, int iCommand )' ) || die; my $hWnd = GetConsoleWindow(); ShowWindow( $hWnd, 0x01 );

    There are probably simpler ways to do this though.

    Steve
    ---
    steve.org.uk

      Thank you!

      You actually answered my question that I asked in Tk::DialogBox as the top window. When I was reading your post, I suddenly realized that to raise the DailogBox to front is not enough. What I should do is to:

      1. Bring console window to font
      2. show DialogBox

      I modified your code a little bit just because I am more used to Win32::API ;-)

      my $api1 = Win32::API->new('kernel32', 'GetConsoleWindow', '', 'N'); my $api2 = Win32::API->new('user32', 'ShowWindow' , 'NN', 'N'); my $i = $api1->Call();; $api2->Call($i, 1); my $dialog = $mw->DialogBox(-title => "Is $host trusted?", -buttons => + ["Yes", "No"]); $dialog->geometry("600x50+0+0"); $dialog->deiconify(); my $answer = $dialog->Show();
        Thanks to both of you for your help. That is what I was looking for but for some reason my console window won't actually come to the foreground.

        I have a perl script that launches another application, i.e. Matlab, so the console window can't be seen in the background. If I do call the ShowWindow() API the console window isn't brought to the foreground in front of the matlab application. Any thoughts on this?