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

Hi all,

Just a quick question, (at least I think that it's quick!).
I've seen on some sites that it's possible to hide the dos window using the Win32::API::Prototype module.
I've installed it but the function "GetConsoleWindow()" seems to be missing.
Does anyone know what I've done wrong, or is there something else I should be using.

Below is the code that supposed to hide the dos console...

If anyone has any idea why this is going screwy or another way to hide the dos console window, I'd be extremely greatful.

Thanks,
Buzzthebuzzsaw.

use Win32::API::Prototype; ApiLink( 'KERNEL32.DLL', 'HWND GetConsoleWindow()' ); ApiLink( 'USER32.DLL', 'BOOL ShowWindow( HWND hWnd, int iCommand )' ); $hWnd = GetConsoleWindow(); print "About to hide the window...\n"; sleep( 1 ); # Hide the window. # BEGIN CALLOUT A ShowWindow( $hWnd, 0x00 ); # END CALLOUT A print "Now let's count to 100:\n"; foreach my $Count ( 1..100 ) { print "$Count, "; } print "\n"; sleep( 5 ); print "About to restore the window...\n"; # Restore the window. # BEGIN CALLOUT B ShowWindow( $hWnd, 0x04 ); # END CALLOUT B print "Restored!\n";
  • Comment on Hiding the dos console where perl program was called from in windows?
  • Download Code

Replies are listed 'Best First'.
Re: Hiding the dos console where perl program was called from in windows?
by Mr. Muskrat (Canon) on Nov 13, 2002 at 23:21 UTC

    If you are using ActiveState Perl, the easiest way is to simply associate a different file extension (.wpl for example) with the wperl.exe. Then when you run a .wpl script, it will run without a DOS console.

    If you are using another distribution of Perl, then you are not out of luck either...

    Jenda's GUI Scripts has info on hacking perl.exe and also this snippet - Thanks Jenda!

    use Win32::GUI; BEGIN {Win32::GUI::Hide(scalar(Win32::GUI::GetPerlWindow()))};

    I seem to be forgeting one or two other ways but this should put you on the right track.

      Excellent!

      That's worked a treat.
      Those windows were beginning to bug me.

      Thanks a million guys.

Re: Hiding the dos console where perl program was called from in windows?
by vek (Prior) on Nov 13, 2002 at 23:19 UTC
Re: Hiding the dos console where perl program was called from in windows?
by Anonymous Monk on Nov 13, 2002 at 23:53 UTC

    Hi. This question was asked recently. There are several non-Win32::GUI solutions. personally I think Win32::GUI is a bit overkill unless you actually plan on using it for it's GUI functions.

      Thanks for the link.
      I did a search on the site beforehand, and didn't get anything that I needed, which is why I asked the question (unknowingly) again.

      I had a look at the other ways of getting rid of the console but, from what I can see, the easiest way of doing it is the Win32::GUI way.

      Anyways,
      Thanks for the help.