GetWindowRect 在 Windows 10 中有偏移 [英] GetWindowRect has offset in Windows 10

查看:18
本文介绍了GetWindowRect 在 Windows 10 中有偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中使用 GetWindowRect 来获取桌面上窗口的坐标.这在我在这里进行测试的十几台 PC(XP-W8.1)上运行良好,但在我的一台带触摸屏的 W10 PC 上却不行:坐标与左上角有偏移.我搜索了 Windows 10 中的错误和与监视器相关的内容,但找不到任何内容,但这似乎是一个常用功能,并且问题很容易重现.

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.

谁有线索?

代码,简化:

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)

推荐答案

您的程序不支持 DPI,因此受制于 DPI 虚拟化.这意味着 GetWindowRect 等函数返回的坐标将是虚拟坐标,因此与真实的屏幕坐标不匹配.

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.

这篇关于GetWindowRect 在 Windows 10 中有偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆