问题
I use GetWindowRect in my program to get the coordinates of a window on the desktop. This works fine on a dozen or so PCs I have here for testing (XP-W8.1) but not on my one W10 PC with touch screen: the coordinates have an offset to the top-left. I googled both for a bug in Windows 10 and for something monitor related but cannot find anything, yet this seems like a commonly used function and the problem is easy to reproduce.
Anyone got any clues?
Code, simplified:
hwnd = FindWindow(NULL, windowname);
if (hwnd) {
TRect r;
GetWindowRect(hwnd, &r);
}
HWND hdt = GetDesktopWindow();
HDC dcdt = GetWindowDC(hdt);
// bitblt canvas to get window (won't work for high DPI setting)
回答1:
Your program is not DPI aware and so is subject to DPI virtualization. That means that the coordinates returned by functions like GetWindowRect
will be virtualized coordinates and so will not match the true screen coordinates.
来源:https://stackoverflow.com/questions/30323426/getwindowrect-has-offset-in-windows-10