Lobsternator
Lobsternator

Reputation: 109

How to know if a window is maximized using pywin32?

I need to check if a window is maximized using pywin32. I'm on a windows 10 machine.

I have looked through the documentation but can't find a straight solution, any leads?

Upvotes: 3

Views: 2421

Answers (1)

Barmak Shemirani
Barmak Shemirani

Reputation: 31669

Use GetWindowPlacement API.

In pywin32, win32gui.GetWindowPlacement will return a tuple which can be tested as follows:

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

Upvotes: 7

Related Questions