def BringHwndToFront(hWnd, invalidate=True): if hWnd is None: return hWnd = GetAncestor(hWnd, GA_ROOT) if not IsWindow(hWnd): return # If the window is in a minimized state, restore now if IsIconic(hWnd): ShowWindow(hWnd, SW_RESTORE) BringWindowToTop(hWnd) UpdateWindow(hWnd) # Check to see if we are the foreground thread foregroundHwnd = GetForegroundWindow() foregroundThreadID = GetWindowThreadProcessId(foregroundHwnd, None) ourThreadID = GetCurrentThreadId() # If not, attach our thread's 'input' to the foreground thread's if foregroundThreadID != ourThreadID: AttachThreadInput(foregroundThreadID, ourThreadID, True) ShowWindow(hWnd, SW_SHOWNA) BringWindowToTop(hWnd) # Force our window to redraw if invalidate: InvalidateRect(hWnd, None, True) if foregroundThreadID != ourThreadID: AttachThreadInput(foregroundThreadID, ourThreadID, False)
def PyGetWindowThreadProcessId(hWnd): """ Retrieves the identifier of the thread and process that created the specified window. int threadId, int processId = GetWindowThreadProcessId(hWnd) """ dwProcessId = DWORD() threadId = GetWindowThreadProcessId(hWnd, byref(dwProcessId)) return threadId, dwProcessId.value
def GetWindowProcessName(hWnd): dwProcessId = DWORD() GetWindowThreadProcessId(hWnd, byref(dwProcessId)) return GetProcessName(dwProcessId.value)
def callback(hwnd, hwnds): if IsWindowVisible(hwnd): _, result = GetWindowThreadProcessId(hwnd) if result == pid: hwnds.append(hwnd) return True