Windows-在启动信息中使用wShowWindow进行Popen不会影响显示 [英] Windows - Popen with wShowWindow in startupinfo not affecting display

查看:146
本文介绍了Windows-在启动信息中使用wShowWindow进行Popen不会影响显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些简单的事情,例如让calc.exe开始最小化,但这没有发生.

import subprocess
import win32gui
import win32con

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = win32con.SW_SHOWMINIMIZED
x = subprocess.Popen("calc.exe", startupinfo = info)

无论我为wShowWindow提供什么,它都会像往常一样弹出.

解决方案

我认为您已经知道了这一点,但是为了其他读者的利益,这是我的看法:

问题与calc.exe程序特别相关,与Python或您的代码无关.为了证明这一点,请尝试启动"notepad.exe"(或"wordpad.exe"),它会起作用-还要注意,您可能需要根据目标文件的位置提供目标.exe文件的完整路径.

根据STARTUPINFO结构,wShowWindow成员,具体来说是错误的:

对于GUI进程,第一次调用ShowWindow时,将忽略其nCmdShow参数wShowWindow指定默认值.在随后的ShowWindow调用中,如果ShowWindow的nCmdShow参数设置为SW_SHOWDEFAULT,则使用wShowWindow成员.

因此,这意味着,程序第一次启动并调用ShowWindow()时,它将完全忽略您为STARTUPINFO结构中的wShowWindow传递的任何内容.然后,如果再次调用ShowWindow(),并且程序将nCmdShow参数设置为SW_SHOWDEFAULT的情况下调用ShowWindow(),它将使用您提供的wShowWindow值.

因此,如果程序本身为ShowWindow()中的nCmdShow提供了自己的值,则似乎不可能隐藏GUI窗口,因此,看看哪些程序可以执行此操作似乎是反复试验,例如记事本. .exe可以将其隐藏,而calc.exe则不能.

I'm trying to do something simple like get calc.exe to start minimized, but it's not happening.

import subprocess
import win32gui
import win32con

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = win32con.SW_SHOWMINIMIZED
x = subprocess.Popen("calc.exe", startupinfo = info)

It pops up the same as always, no matter what I provide for wShowWindow.

解决方案

I think you've already figured this out, but for the benefit of other readers here's my take:

The problem has something to do specifically with the calc.exe program, not Python nor your code. To prove it, try launching "notepad.exe" (or "wordpad.exe") and it will work -- also note you may need to supply the full path to the target .exe file depending on where it is.

Specifically what is wrong, is according to the STARTUPINFO structure, the wShowWindow member:

For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored wShowWindow specifies the default value. In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT.

So what this means is, the first time a program starts, and calls ShowWindow(), it completely ignores whatever you have passed in for wShowWindow in the STARTUPINFO structure. Then, upon another call to ShowWindow(), it will only use your provided value for wShowWindow if the program calls ShowWindow() with its nCmdShow parameter set to SW_SHOWDEFAULT.

So, it seems to be impossible to hide a GUI window if the program itself provides its own value for nCmdShow in ShowWindow(), so it just seems like trial and error to see which programs do that, such as notepad.exe allows you to hide it, while calc.exe you cannot.

这篇关于Windows-在启动信息中使用wShowWindow进行Popen不会影响显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆