【发布时间】:2014-03-18 18:02:18
【问题描述】:
好的,所以在下面的代码中
import win32api
import win32gui
hwnd = win32api.ShellExecute(None, "open", "notepad.exe", "test.txt", None, 6)
rect = win32gui.GetWindowRect(hwnd)
我成功打开记事本并收到返回值>32,表示执行成功。在文档中:http://timgolden.me.uk/pywin32-docs/win32api__ShellExecute_meth.html 返回值被指定为实例句柄,因此我希望能够将此句柄用作 GetWindowRect 调用的参数。文档:http://timgolden.me.uk/pywin32-docs/win32gui__GetWindowRect_meth.html
在我的调试器中,我可以看到 hwnd 等于 {long}42,我的 GetWindowRect 调用返回错误 1400,窗口句柄无效。
那么为什么句柄是错误的,我怎样才能得到一个可用的句柄呢?
【问题讨论】:
-
即使你取回了一个有效的句柄,实例句柄也不同于窗口句柄。