def findControls(topHwnd,
wantedText=None,
wantedClass=None,
selectionFunction=None):
'''Find controls.
You can identify controls using captions, classes, a custom selection
function, or any combination of these. (Multiple selection criteria are
ANDed. If this isn't what's wanted, use a selection function.)
Arguments:
topHwnd The window handle of the top level window in which the
required controls reside.
wantedText Text which the required controls' captions must contain.
wantedClass Class to which the required controls must belong.
selectionFunction Control selection function. Reference to a function
should be passed here. The function should take hwnd as
an argument, and should return True when passed the
hwnd of a desired control.
Returns: The window handles of the controls matching the
supplied selection criteria.
Usage example: optDialog = findTopWindow(wantedText="Options")
def findButtons(hwnd, windowText, windowClass):
return windowClass == "Button"
buttons = findControl(optDialog, wantedText="Button")
'''
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)
win_GUI.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录