Skip to content

Instantly share code, notes, and snippets.

@t2psyto
Created January 27, 2014 08:04
Show Gist options
  • Select an option

  • Save t2psyto/8644661 to your computer and use it in GitHub Desktop.

Select an option

Save t2psyto/8644661 to your computer and use it in GitHub Desktop.
IE から flash object のウィンドウハンドルと座標を取得
def searchChildWindows(currentHwnd, wantedText="",wantedClass="", wantedFunction=""):
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
#print "childWindows:", len(childWindows)
count = 0
for childHwnd, windowText, windowClass in childWindows:
#print count
count = count + 1
#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
#print childHwnd, windowText, windowClass
results.append(childHwnd)
return results
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)))
import win32gui
hwnd = win32gui.GetDesktopWindow()
hwnd2 = win32gui.FindWindowEx(hwnd, None, "IEFrame", None)
results = searchChildWindows(hwnd2,wantedClass="TabWindowClass")
for local_hwnd in results:
print local_hwnd, win32gui.GetClassName(local_hwnd), win32gui.GetWindowText(local_hwnd)
results2 = searchChildWindows(local_hwnd,wantedClass='MacromediaFlashPlayerActiveX')
print results2
for local_hwnd2 in results2:
print "\t", local_hwnd2, win32gui.GetClassName(local_hwnd2), win32gui.GetWindowText(local_hwnd2), win32gui.GetWindowRect(local_hwnd2)
@t2psyto
Copy link
Author

t2psyto commented Jan 27, 2014

ここを参考にしました。
http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html
http://okamerin.com/nc/title/334.htm - flashのハンドルを取得してみよう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment