From: Jan Dubois Date: Tue, 12 Feb 2002 00:56:31 +0000 (-0800) Subject: Re: [PATCH 5.6.1] Win32: Give user control over window creation behavior of system... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02637f4cf632ad1b1402d154f783a4db5a81d968;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH 5.6.1] Win32: Give user control over window creation behavior of system() function Message-ID: <4llh6uc4gnqtk3csmfoqed3t6q85436bb1@4ax.com> p4raw-id: //depot/perl@14657 --- diff --git a/lib/Win32.pod b/lib/Win32.pod index 842e484..95f7562 100644 --- a/lib/Win32.pod +++ b/lib/Win32.pod @@ -253,6 +253,20 @@ The function returns the menu id of the selected push button: [EXT] Loads the DLL LIBRARYNAME and calls the function DllRegisterServer. +=item Win32::SetChildShowWindow(SHOWWINDOW) + +[CORE] Sets the I of child processes started by system(). +By default system() will create a new console window for child +processes if Perl itself is not running from a console. Calling +SetChildShowWindow(0) will make these new console windows invisible. +Calling SetChildShowWindow() without arguments reverts system() to the +default behavior. The return value of SetChildShowWindow() is the +previous setting or C. + +[EXT] The following symbolic constants for SHOWWINDOW are available +(but not exported) from the Win32 module: SW_HIDE, SW_SHOWNORMAL, +SW_SHOWMINIMIZED, SW_SHOWMAXIMIZED and SW_SHOWNOACTIVATE. + =item Win32::SetCwd(NEWDIRECTORY) [CORE] Sets the current active drive and directory. This function does not diff --git a/win32/win32.c b/win32/win32.c index 52d0924..e0cdfc0 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3667,6 +3667,10 @@ win32_spawnvp(int mode, const char *cmdname, const char *const *argv) else { create |= CREATE_NEW_CONSOLE; } + if (w32_use_showwindow) { + StartupInfo.dwFlags |= STARTF_USESHOWWINDOW; + StartupInfo.wShowWindow = w32_showwindow; + } DEBUG_p(PerlIO_printf(Perl_debug_log, "Spawning [%s] with [%s]\n", cname,cmd)); @@ -4003,6 +4007,32 @@ win32_dynaload(const char* filename) */ static +XS(w32_SetChildShowWindow) +{ + dXSARGS; + BOOL use_showwindow = w32_use_showwindow; + /* use "unsigned short" because Perl has redefined "WORD" */ + unsigned short showwindow = w32_showwindow; + + if (items > 1) + Perl_croak(aTHX_ "usage: Win32::SetChildShowWindow($showwindow)"); + + if (items == 0 || !SvOK(ST(0))) + w32_use_showwindow = FALSE; + else { + w32_use_showwindow = TRUE; + w32_showwindow = (unsigned short)SvIV(ST(0)); + } + + EXTEND(SP, 1); + if (use_showwindow) + ST(0) = sv_2mortal(newSViv(showwindow)); + else + ST(0) = &PL_sv_undef; + XSRETURN(1); +} + +static XS(w32_GetCwd) { dXSARGS; @@ -4488,6 +4518,7 @@ Perl_init_os_extras(void) newXS("Win32::GetLongPathName", w32_GetLongPathName, file); newXS("Win32::CopyFile", w32_CopyFile, file); newXS("Win32::Sleep", w32_Sleep, file); + newXS("Win32::SetChildShowWindow", w32_SetChildShowWindow, file); /* XXX Bloat Alert! The following Activeware preloads really * ought to be part of Win32::Sys::*, so they're not included diff --git a/win32/win32.h b/win32/win32.h index f5c04b6..299d8f1 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -353,6 +353,8 @@ struct thread_intern { # ifdef USE_RTL_THREAD_API void * retv; /* slot for thread return value */ # endif + BOOL Wuse_showwindow; + WORD Wshowwindow; }; #ifdef USE_5005THREADS @@ -421,12 +423,16 @@ DllExport int win32_async_check(pTHX); # define w32_crypt_buffer (thr->i.Wcrypt_buffer) # define w32_servent (thr->i.Wservent) # define w32_init_socktype (thr->i.Winit_socktype) +# define w32_use_showwindow (thr->i.Wuse_showwindow) +# define w32_showwindow (thr->i.Wshowwindow) #else # define w32_strerror_buffer (PL_sys_intern.thr_intern.Wstrerror_buffer) # define w32_getlogin_buffer (PL_sys_intern.thr_intern.Wgetlogin_buffer) # define w32_crypt_buffer (PL_sys_intern.thr_intern.Wcrypt_buffer) # define w32_servent (PL_sys_intern.thr_intern.Wservent) # define w32_init_socktype (PL_sys_intern.thr_intern.Winit_socktype) +# define w32_use_showwindow (PL_sys_intern.thr_intern.Wuse_showwindow) +# define w32_showwindow (PL_sys_intern.thr_intern.Wshowwindow) #endif /* USE_5005THREADS */ /* UNICODE<>ANSI translation helpers */