如何在Python中使用win32gui关闭带有句柄的窗口 [英] how do I close window with handle using win32gui in Python
本文介绍了如何在Python中使用win32gui关闭带有句柄的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用Python中的win32gui库获得了要定位的窗口的句柄
I have obtained the handle of a window I want to target, with win32gui library in Python
如何关闭窗口?
我有以下代码,第二行完成了我打算做的事
I have the following code, the second line did what I intended to do
但最后一行似乎是错误的.
but the last line seems to be wrong.
handle = win32gui.FindWindow(None, r'Notepad++')
win32gui.SetForegroundWindow(handle)
win32gui.CloseWindow(handle)
我还想知道是否只想关闭窗口,第二行是否必要?
I also want to know if I just want to close the window, is the second line necessary?
除此之外,我注意到一件小事,对此感到好奇:
Besides that, I notice a minor thing, and I am curious about it:
如果我尝试
win32gui.CloseWindow(handle)
在Python shell中,我得到类似的东西:
in Python shell, I get something like:
2500276L
但如果我尝试
handle = win32gui.CloseWindow(handle)
print handle
然后我得到
2500276
最后的"L"有什么区别吗?
does the 'L' in the end make any difference?
感谢您的关注!
推荐答案
尝试:
import win32con
win32gui.PostMessage(handle,win32con.WM_CLOSE,0,0)
这应该有效.
这篇关于如何在Python中使用win32gui关闭带有句柄的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文