mhammond / pywin32

Python for Windows (pywin32) Extensions
4.91k stars 783 forks source link

Add dpi_aware Parameter to win32gui.GetWindowRect for Actual Window Size #2117

Closed songyuc closed 10 months ago

songyuc commented 10 months ago

Hi, guys! I'm suggesting the addition of a dpi_aware parameter to win32gui.GetWindowRect to accurately reflect the window size on high-DPI displays.

Problem Description

When using win32gui.GetWindowRect(hwnd) to get the window size, the dimensions returned are not always accurate on high-DPI displays. This leads to some layout and rendering issues.

Usage Scenario

This feature would be particularly useful for developers working on applications that need to adapt to different display settings, especially on high-DPI screens.

Example Code


# Current usage
rect = win32gui.GetWindowRect(hwnd)

# Suggested usage
rect = win32gui.GetWindowRect(hwnd, dpi_aware=True)
mhammond commented 10 months ago

GetWindowRect() just wraps the Windows GetWindowRect() function - it has no such param, so it doesn't make sense to add it here.