in reply to Bring Win32 command window to foreground

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

Replies are listed 'Best First'.
Re^2: Bring Win32 command window to foreground
by pg (Canon) on Oct 11, 2004 at 21:39 UTC

    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?