Shi Jie Tio
Shi Jie Tio

Reputation: 2529

How to maximize an inactive window?

I have multiple window, but i wish to maximize one of the window only, below is my scripts:

import win32gui, win32con
win32gui.ShowWindow('C:/Desktop/UD.ca', win32con.SW_MAXIMIZE)

After run this script i get bellow error:

Error

TypeError: The object is not a PyHANDLE object

Anyone have idea on this?

Upvotes: 2

Views: 2621

Answers (2)

cosminm
cosminm

Reputation: 11

This approach worked for me, I combined it with another code to find my window, and worked just fine, thank you. I am looking for a window named "outlook", bring it forward then maximize.

 # maximize window
top_windows = []
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
    if "outlook" in i[1].lower():
        print(i)
        hwnd = win32gui.GetForegroundWindow()
        win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
        break

Upvotes: 1

darksky
darksky

Reputation: 2100

You need the HWND of the window that you want to maximize. 'C:/Desktop/UD.ca' is not an HWND. Think of it as a unique ID for a window.

As an example, you can get the HWND of the foreground window by

hwnd = win32gui.GetForegroundWindow()

and then pass that in the call to ShowWindow,

win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)

If you want to search all visible Windows for one that contains a title, see Get HWND of each Window?

Upvotes: 2

Related Questions