Win32在C+&#x2B中获得未量的虚拟桌面大小。

发布于 2025-01-26 01:31:27 字数 929 浏览 1 评论 0原文

在C ++应用程序上工作,试图将鼠标从坐标映射到全屏窗口。

getPhysicalCursorPos(& mouse_point);获得鼠标坐标,该均可返回相对于原点0,0的坐标。这会导致问题,因为鼠标正在“超出监视器”的“范围”,因为窗口的大小缩小了窗口。例如,当它在右下角时返回{3839,1079},但是Windows将总桌面大小计算为3200x1080。 (此示例两个1080p显示器并排,左侧具有100%的缩放,右图具有150%的缩放))

检索虚拟桌面尺寸:

unsigned int vScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
unsigned int vScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);

但这是返回桌面的桌面,其中较高的DPI监视器较小,因此Dual 1080p较小监视配置为3840x1080,它返回3200x1080(上面的配置)。

我已经尝试使用getSystemmetricsfordpi使用96 dpi(100%),但它返回与上述相同的返回:

unsigned int vScreenWidth = GetSystemMetricsForDpi(SM_CXVIRTUALSCREEN, 96 /* 100% scaling*/);
unsigned int vScreenHeight = GetSystemMetricsForDpi(SM_CYVIRTUALSCREEN, 96 /* 100% scaling*/);

上面在上面我的混合缩放示例中返回3200x1080,尽管明确地告诉强迫使用100%缩放。

还有其他方法可以获取未缩放的虚拟桌面尺寸吗?

请注意,该应用程序不知道

Working on a C++ application, trying to map the mouse from the coordinates to the full screen windows.

Getting the mouse coordinates with GetPhysicalCursorPos(&mouse_point); which returns the coordinates relative to the origin 0,0. This is causing issues because the mouse is going "out of bounds" of the monitors because windows is scaling them down in size. E.g. it returns {3839, 1079} when it's at the bottom right corner, but Windows computes the total desktop size as 3200x1080. (this example two 1080p monitors, side by side, left has 100% scaling, right has 150% scaling)

Retrieving the virtual desktop size with:

unsigned int vScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
unsigned int vScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);

But this is returning a desktop where the monitors with a higher DPI are smaller so for a dual 1080p monitor config of 3840x1080, it returns 3200x1080 (configuration above).

I've tried using GetSystemMetricsForDpi with 96 DPI (100%) but it returns the same as above:

unsigned int vScreenWidth = GetSystemMetricsForDpi(SM_CXVIRTUALSCREEN, 96 /* 100% scaling*/);
unsigned int vScreenHeight = GetSystemMetricsForDpi(SM_CYVIRTUALSCREEN, 96 /* 100% scaling*/);

The above also returns 3200x1080 in my mixed scaling example above, despite explicitly telling it to force use 100% scaling.

Is there any other way to get the un-scaled virtual desktop size?

Note the application is NOT DPI aware.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够 2025-02-02 01:31:27

多亏了@Raymondchen,我能够通过调用setThreadDpiawarenessContext(dpi_awareness_context_per_per_monitor_aware_v2); getSystemmetricsfordpi

现在,它返回完整的虚拟桌面尺寸。

Thanks to @RaymondChen I was able to fix it by calling SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); prior to GetSystemMetricsForDpi.

It now returns the full virtual desktop size.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文