简体   繁体   中英

Using Python, how can I detect whether a program is minimized or maximized?

I am trying to detect if a window is open using win32gui.IsIconic(hWnd). What exactly do I put in to substitute hWnd?

My goal is pretty simple: If a program, for example Notepad, is maximized, I want a boolean to be true, and if not, it's false.

I am not 100% familiar with programming terms as I am a bit on the newer side of programming, so examples/specifics help tops.

This would probably work.

window = win32gui.FindWindow("Notepad", None)
if window:
    tup = win32gui.GetWindowPlacement(window)
    if tup[1] == win32con.SW_SHOWMAXIMIZED:
        minimized = False
    elif tup[1] == win32con.SW_SHOWMINIMIZED:
        minimized = True
    elif tup[1] == win32con.SW_SHOWNORMAL:
        normal = True

The code is from this answer: Duplicate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM