Windows 7: how to bring a window to the front no matter what other window has focus?

后端 未结 9 1783
走了就别回头了
走了就别回头了 2020-11-28 08:04

I\'m implementing a task-bar replacement, dock-like application-switcher style program. It\'s doing some unique stuff with OpenGL, and with keyboard shortcuts, so the way it

9条回答
  •  鱼传尺愫
    2020-11-28 08:38

    This is how I got mine working:

    import win32gui
    from win32con import (SW_SHOW, SW_RESTORE)
    
    def get_windows_placement(window_id):
        return win32gui.GetWindowPlacement(window_id)[1]
    
    def set_active_window(window_id):
        if get_windows_placement(window_id) == 2:
            win32gui.ShowWindow(window_id, SW_RESTORE)
        else:
            win32gui.ShowWindow(window_id, SW_SHOW)
        win32gui.SetForegroundWindow(window_id)
        win32gui.SetActiveWindow(window_id)
    

提交回复
热议问题