本文整理汇总了Python中win32gui.EnumWindows方法的典型用法代码示例。如果您正苦于以下问题:Python win32gui.EnumWindows方法的具体用法?Python win32gui.EnumWindows怎么用?Python win32gui.EnumWindows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32gui
的用法示例。
在下文中一共展示了win32gui.EnumWindows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_all_windows
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def get_all_windows(cls):
def function(handle, argument):
argument.append(Window(handle))
argument = []
win32gui.EnumWindows(function, argument)
return argument
# @classmethod
# def get_window_by_executable(cls, executable):
# def function(handle, argument):
# title = windll.user32.GetWindowText(handle)
# print "title: %r" % title
# windll.user32.EnumWindows(function, argument)
#=======================================================================
# Methods for initialization and introspection.
示例2: enumCallback
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def enumCallback(hwnd, args):
"""
Will get called by win32gui.EnumWindows, once for each
top level application window.
"""
proc = args[0]
windowName = args[1]
try:
# Get window title
title = win32gui.GetWindowText(hwnd)
# Is this our guy?
if title.find(windowName) == -1:
win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, args)
return
# Send WM_CLOSE message
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
except:
pass
示例3: init
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def init(debug :bool =False) -> Dict[int, Tuple[int, int, int, int]]:
"""Finds the game window and returns its coords."""
if platform.release() == "10":
ctypes.windll.shcore.SetProcessDpiAwareness(2)
else:
ctypes.windll.user32.SetProcessDPIAware()
def window_enumeration_handler(hwnd, top_windows):
"""Add window title and ID to array."""
top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))
if debug:
window_name = "debugg"
else:
window_name = "play ngu idle"
top_windows = []
windows = []
candidates = {}
win32gui.EnumWindows(window_enumeration_handler, top_windows)
windows = [window[0] for window in top_windows if window_name in window[1].lower()]
for window in windows:
candidates[window] = Window.winRect(window)
return candidates
示例4: raise_mpv
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def raise_mpv():
# This workaround is madness. Apparently SetForegroundWindow
# won't work randomly, so I have to call ShowWindow twice.
# Once to hide the window, and again to successfully raise the window.
try:
top_windows = []
fg_win = win32gui.GetForegroundWindow()
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
if " - mpv" in i[1].lower():
if i[0] != fg_win:
win32gui.ShowWindow(i[0], 6) # Minimize
win32gui.ShowWindow(i[0], 9) # Un-minimize
break
except Exception:
print("Could not raise MPV.")
traceback.print_exc()
示例5: enumChildCallback
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def enumChildCallback(hwnd, args):
"""
Will get called by win32gui.EnumWindows, once for each
top level application window.
"""
proc = args[0]
windowName = args[1]
try:
# Get window title
title = win32gui.GetWindowText(hwnd)
# Is this our guy?
if title.find(windowName) == -1:
return
# Send WM_CLOSE message
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
except:
pass
#print sys.exc_info()
示例6: enumCallback
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def enumCallback(hwnd, windowName):
"""
Will get called by win32gui.EnumWindows, once for each
top level application window.
"""
try:
# Get window title
title = win32gui.GetWindowText(hwnd)
# Is this our guy?
if title.find(windowName) == -1:
win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, windowName)
return
# Send WM_CLOSE message
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
except:
pass
示例7: enumChildCallback
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def enumChildCallback(hwnd, windowName):
"""
Will get called by win32gui.EnumWindows, once for each
top level application window.
"""
try:
# Get window title
title = win32gui.GetWindowText(hwnd)
# Is this our guy?
if title.find(windowName) == -1:
return
# Send WM_CLOSE message
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
except:
pass
#print sys.exc_info()
示例8: closeApp
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def closeApp(self, hProcess, title):
"""
Close Application by window title
"""
try:
win32gui.EnumWindows(FileWriterLauncherGui.enumCallback, title)
if proc is not None:
win32event.WaitForSingleObject(hProcess, 5 * 1000)
win32api.CloseHandle(hProcess)
for pid in self.genChildProcesses(proc):
try:
handle = win32api.OpenProcess(1, False, pid)
win32process.TerminateProcess(handle, -1)
win32api.CloseHandle(handle)
except:
pass
except:
pass
示例9: TestEnumWindows
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def TestEnumWindows():
windows = []
classes = {}
win32gui.EnumWindows(_MyCallback, (windows, classes))
print "Enumerated a total of %d windows with %d classes" % (len(windows),len(classes))
if "tooltips_class32" not in classes:
print "Hrmmmm - I'm very surprised to not find a 'tooltips_class32' class."
示例10: kill
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def kill(self, gracePeriod=5000):
"""
Kill process. Try for an orderly shutdown via WM_CLOSE. If
still running after gracePeriod (5 sec. default), terminate.
"""
win32gui.EnumWindows(self.__close__, 0)
if self.wait(gracePeriod) != win32event.WAIT_OBJECT_0:
win32process.TerminateProcess(self.hProcess, 0)
win32api.Sleep(100) # wait for resources to be released
示例11: __close__
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def __close__(self, hwnd, dummy):
"""
EnumWindows callback - sends WM_CLOSE to any window
owned by this process.
"""
TId, PId = win32process.GetWindowThreadProcessId(hwnd)
if PId == self.PId:
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
示例12: get_all_windows
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def get_all_windows(cls):
def function(handle, argument):
argument.append(cls.get_window(handle))
argument = []
win32gui.EnumWindows(function, argument)
return argument
示例13: get_hwnds_for_pid
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def get_hwnds_for_pid(pid):
def callback(hwnd, hwnds):
# if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
# print hwnd
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds
示例14: _windowEnumerationHandler
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def _windowEnumerationHandler(hwnd, resultList):
'''Pass to win32gui.EnumWindows() to generate list of window handle,
window text, window class tuples.'''
resultList.append((hwnd,
win32gui.GetWindowText(hwnd),
win32gui.GetClassName(hwnd)))
示例15: activegamewindow
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import EnumWindows [as 别名]
def activegamewindow():
gamepid = findgame()
if gamepid is not None:
win32gui.EnumWindows(enum_window_callback, gamepid)