Exemplo n.º 1
0
 def enum_windows_cb(hwnd, lparam):
     if not IsWindowVisible(hwnd):
         log("window %#x is not visible", hwnd)
         return True
     pid = c_ulong()
     thread_id = GetWindowThreadProcessId(hwnd, byref(pid))
     if pid==ourpid:
         log("skipped our own window %#x, thread id=%#x", hwnd, thread_id)
         return True
     rect = RECT()
     if GetWindowRect(hwnd, byref(rect))==0:
         log("GetWindowRect failure")
         return True
     if hwnd==taskbar:
         log("skipped taskbar")
         return True
     #skipping IsWindowEnabled check
     length = GetWindowTextLengthW(hwnd)
     buf = create_unicode_buffer(length+1)
     if GetWindowTextW(hwnd, buf, length+1)>0:
         window_title = buf.value
     else:
         window_title = ''
     left, top, right, bottom = rect.left, rect.top, rect.right, rect.bottom
     w = right-left
     h = bottom-top
     if left<=-32000 or top<=-32000:
         log("%r is not visible: %s", window_title, (left, top, w, h))
     if w<=0 and h<=0:
         log("skipped invalid window size: %ix%i", w, h)
         return True
     windows[hwnd] = (window_title, (left, top, w, h))
     return True
Exemplo n.º 2
0
 def enum_windows_cb(hwnd, lparam):
     if not IsWindowVisible(hwnd):
         l("skipped invisible window %#x", hwnd)
         return True
     pid = c_int()
     thread_id = GetWindowThreadProcessId(hwnd, byref(pid))
     if pid == ourpid:
         l("skipped our own window %#x", hwnd)
         return True
     #skipping IsWindowEnabled check
     length = GetWindowTextLengthW(hwnd)
     buf = create_unicode_buffer(length + 1)
     if GetWindowTextW(hwnd, buf, length + 1) > 0:
         window_title = buf.value
     else:
         window_title = ''
     l(
         "get_shape_rectangles() found window '%s' with pid=%i and thread id=%i",
         window_title, pid, thread_id)
     rect = RECT()
     if GetWindowRect(hwnd, byref(rect)) == 0:
         l("GetWindowRect failure")
         return True
     left, top, right, bottom = rect.left, rect.top, rect.right, rect.bottom
     if right < 0 or bottom < 0:
         l("skipped offscreen window at %ix%i", right, bottom)
         return True
     if hwnd == taskbar:
         l("skipped taskbar")
         return True
     #dirty way:
     if window_title == 'Program Manager':
         return True
     #this should be the proper way using GetTitleBarInfo (but does not seem to work)
     #import ctypes
     #from ctypes.windll.user32 import GetTitleBarInfo        #@UnresolvedImport
     #from ctypes.wintypes import (DWORD, RECT)
     #class TITLEBARINFO(ctypes.Structure):
     #    pass
     #TITLEBARINFO._fields_ = [
     #    ('cbSize', DWORD),
     #    ('rcTitleBar', RECT),
     #    ('rgstate', DWORD * 6),
     #]
     #ti = TITLEBARINFO()
     #ti.cbSize = sizeof(ti)
     #GetTitleBarInfo(hwnd, byref(ti))
     #if ti.rgstate[0] & win32con.STATE_SYSTEM_INVISIBLE:
     #    log("skipped system invisible window")
     #    return True
     w = right - left
     h = bottom - top
     l("shape(%s - %#x)=%s", window_title, hwnd, (left, top, w, h))
     if w <= 0 and h <= 0:
         l("skipped invalid window size: %ix%i", w, h)
         return True
     if left == -32000 and top == -32000:
         #there must be a better way of skipping those - I haven't found it
         l("skipped special window")
         return True
     #now clip rectangle:
     if left < 0:
         left = 0
         w = right
     if top < 0:
         top = 0
         h = bottom
     rectangles.append((left, top, w, h))
     return True