jezza
jezza

Reputation: 161

DPI Scaling Level affecting win32gui GetWindowRect in Python

When GetWindowRect() is called in Python, the values it returns are inaccurate if a DPI scaling level of anything but 100% is used. Is there any way to get around this, or mathematically adjust?

Upvotes: 6

Views: 2084

Answers (1)

Mike Souder
Mike Souder

Reputation: 541

You can make your program DPI aware using windll from ctypes:

from ctypes import windll

# Make program aware of DPI scaling
user32 = windll.user32
user32.SetProcessDPIAware()

From that point on calls like GetWindowRect() should return the proper values. I stumbled upon this solution a while back trying to get Pyautogui to give me proper screenshots.

Upvotes: 9

Related Questions