本文整理匯總了Python中win32gui.EnumChildWindows方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.EnumChildWindows方法的具體用法?Python win32gui.EnumChildWindows怎麽用?Python win32gui.EnumChildWindows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32gui
的用法示例。
在下文中一共展示了win32gui.EnumChildWindows方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: attach
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def attach(self, device):
if self.device is not None:
print "Warning: already attached to a device."
if device is not self.device:
self.detach()
handle = device.hwnd
def callback(hwnd, extra):
extra.add(hwnd)
return True
self.watched_hwnds.add(handle)
try:
# EnumChildWindows may crash for windows have no any child.
# refs: https://mail.python.org/pipermail/python-win32/2005-March/003042.html
win32gui.EnumChildWindows(handle, callback, self.watched_hwnds)
except pywintypes.error:
pass
self.device = device
print "attach to device", device
示例2: dumpWindows
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def dumpWindows(hwnd):
'''Dump all controls from a window
Useful during development, allowing to you discover the structure of the
contents of a window, showing the text and class of all contained controls.
Parameters
----------
hwnd
The window handle of the top level window to dump.
Returns
-------
all windows
Usage example::
replaceDialog = findTopWindow(wantedText='Replace')
pprint.pprint(dumpWindow(replaceDialog))
'''
windows = []
win32gui.EnumChildWindows(hwnd, _windowEnumerationHandler, windows)
return windows
示例3: enumCallback
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def enumCallback(hwnd, self):
title = win32gui.GetWindowText(hwnd)
for name in self.WindowNames:
if title.find(name) > -1:
try:
self.FoundWindowEvent.set()
if self.CloseWindows:
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
except:
pass
else:
try:
win32gui.EnumChildWindows(hwnd, _WindowWatcher.enumChildCallback, self)
except:
pass
return True
示例4: enumCallback
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [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
示例5: enumCallback
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [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
示例6: findSpecifiedWindows
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def findSpecifiedWindows(top_hwnd, numChildWindows=70):
'''
查找某一窗口下指定數量的子窗口
:param top_hwnd: 主窗口句柄
:param numChildWindows: 子窗口數量
:return:子窗口列表,包括子窗口hwnd, title, className
'''
windows = []
try:
win32gui.EnumChildWindows(top_hwnd, _windowEnumerationHandler, windows)
except win32gui.error:
# No child windows
return
for window in windows:
childHwnd, windowText, windowClass = window
windowContent = dumpSpecifiedWindow(childHwnd)
if len(windowContent) == numChildWindows:
return windowContent
# 沒有指定數量的句柄
return
示例7: dumpWindows
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def dumpWindows(hwnd):
"""Dump all controls from a window
Useful during development, allowing to you discover the structure of the
contents of a window, showing the text and class of all contained controls.
Parameters
----------
hwnd
The window handle of the top level window to dump.
Returns
-------
all windows
Usage example::
replaceDialog = findTopWindow(wantedText='Replace')
pprint.pprint(dumpWindow(replaceDialog))
"""
windows = []
win32gui.EnumChildWindows(hwnd, _windowEnumerationHandler, windows)
return windows
示例8: findControls
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def findControls(topHwnd,
wantedText=None,
wantedClass=None,
selectionFunction=None):
def searchChildWindows(currentHwnd):
results = []
childWindows = []
try:
win32gui.EnumChildWindows(currentHwnd,
_windowEnumerationHandler,
childWindows)
except win32gui.error:
# This seems to mean that the control *cannot* have child windows,
# i.e. not a container.
return
for childHwnd, windowText, windowClass in childWindows:
descendentMatchingHwnds = searchChildWindows(childHwnd)
if descendentMatchingHwnds:
results += descendentMatchingHwnds
if wantedText and \
not _normaliseText(wantedText) in _normaliseText(windowText):
continue
if wantedClass and \
not windowClass == wantedClass:
continue
if selectionFunction and \
not selectionFunction(childHwnd):
continue
results.append(childHwnd)
return results
return searchChildWindows(topHwnd)
示例9: dumpWindow
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def dumpWindow(hwnd):
'''Dump all controls from a window into a nested list
Useful during development, allowing to you discover the structure of the
contents of a window, showing the text and class of all contained controls.
Parameters
----------
hwnd
The window handle of the top level window to dump.
Returns
-------
A nested list of controls. Each entry consists of the
control's hwnd, its text, its class, and its sub-controls, if any.
Usage example::
replaceDialog = findTopWindow(wantedText='Replace')
pprint.pprint(dumpWindow(replaceDialog))
'''
windows = []
try:
win32gui.EnumChildWindows(hwnd, _windowEnumerationHandler, windows)
except win32gui.error:
# No child windows
return
windows = [list(window) for window in windows]
for window in windows:
childHwnd, windowText, windowClass = window
window_content = dumpWindow(childHwnd)
if window_content:
window.append(window_content)
return windows
示例10: foreach_window
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def foreach_window(self):
def callback(hwnd, lparam):
title = win32gui.GetWindowText(hwnd).lower()
for window in self.to_close:
if window in title:
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
print "Closed window ({})".format(title)
for window in self.clicks:
if window in title:
self._windows[hwnd] = {
"matches": self.clicks[window],
"to_click": [],
"buttons": []
}
try:
win32gui.EnumChildWindows(hwnd, self.foreach_child(), hwnd)
except:
print "EnumChildWindows failed, moving on."
for button_toclick in self._windows[hwnd]['to_click']:
for button in self._windows[hwnd]['buttons']:
if button_toclick in button['text']:
win32gui.SetForegroundWindow(button['handle'])
win32gui.SendMessage(button['handle'], win32con.BM_CLICK, 0, 0)
print "Clicked on button ({} / {})".format(title, button['text'])
del self._windows[hwnd]
return True
return callback
示例11: findWindow
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import EnumChildWindows [as 別名]
def findWindow(name='',C='',parent=0):
R=[]
def callbck(hwnd, lParam):
title,c = getInfo(hwnd)
if (name=='' or title.startswith(name)) and (C=='' or c==C):
R.append(hwnd)
return True
user32.EnumChildWindows(parent,WNDENUMPROC(callbck),42)
return R