This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, iMath, mmaswg, ohno, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-10-29.05:47:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635486473.91.0.404346556186.issue30082@roundup.psfhosted.org>
In-reply-to
Content
If only force_hide is implemented, based on `wShowWindow=SW_HIDE`, please ensure that it's clearly documented that this option hides the main window (i.e. first top-level window) of any application that doesn't bypass the default behavior of the window manager.

This means a script can't simply use `force_hide=True` universally when running arbitrary commands, since hiding the main window of a GUI app is probably undesired behavior. If it's unknown in advance whether an executable is a console or GUI app, it can be determined via SHGetFileInfoW(). For example:

    import ctypes
    shell32 = ctypes.WinDLL('shell32', use_last_error=True)
    SHGFI_EXETYPE = 0x2000

    def is_gui_exe(path):
        result = shell32.SHGetFileInfoW(path, 0, None, 0, SHGFI_EXETYPE)
        # the high word is non-zero for a GUI app
        return (result >> 16) > 0

    >>> is_gui_exe(r'C:\Windows\pyw.exe')
    True
    >>> is_gui_exe(r'C:\Windows\py.exe')
    False

Regarding the effect of wShowWindow:

If the STARTUPINFO record defines wShowWindow, the value gets used as the normal show command for the first top-level window that's shown in the process. In particular, it overrides the first use (and only the first use) of the commands SW_SHOW, SW_SHOWNORMAL, and SW_SHOWDEFAULT (yes, only the first use of the latter; the documentation is wrong). This affects showing the first top-level window regardless of whether it's explicit via ShowWindow() or implicit via the WS_VISIBLE window style. For the latter, the implicit command is SW_SHOW, which one can override in the CreateWindowW() call by passing x=CW_USEDEFAULT and y as the show command to use. 

To completely ignore the STARTUPINFO wShowWindow value for the main window, an application can use an initial show command that wShowWindow doesn't override, such as SW_HIDE, SW_RESTORE (behaves like SW_SHOWNORMAL on first use), SW_MINIMIZE, or SW_MAXIMIZE. For example, for the first command use ShowWindow(hwnd, SW_HIDE). Subsequently calling ShowWindow(hwnd, SW_SHOWNORMAL) will show the window normally (i.e. active and restored) instead of using the STARTUPINFO wShowWindow command.
History
Date User Action Args
2021-10-29 05:47:53eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, iMath, ohno, mmaswg
2021-10-29 05:47:53eryksunsetmessageid: <1635486473.91.0.404346556186.issue30082@roundup.psfhosted.org>
2021-10-29 05:47:53eryksunlinkissue30082 messages
2021-10-29 05:47:53eryksuncreate