Windows 10中的GetWindowRect已偏移 [英] GetWindowRect has offset in Windows 10

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

问题描述

我在程序中使用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.

任何人都有任何线索吗?

Anyone got any clues?

简化的代码:

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.

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

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