问题描述
我遇到了一个有趣的问题。至少在Vista中,当桌面DPI设置未设为100%时,getSystemMetrics(SM_CXSCREEN)返回的值不正确。例如,我在1366x768屏幕上尝试了150%,并且getSystemMetrics()返回911而不是1366(和1366 / 1.5〜911)
I've run into an interesting problem. At least in Vista, getSystemMetrics(SM_CXSCREEN) returns an incorrect value when the desktop DPI settings aren't set at 100%. For example, I tried 150% in a 1366x768 screen and getSystemMetrics() returns 911 instead of 1366 (and 1366 / 1.5 ~ 911)
根据MSDN,getSystemMetrics( SM_CXSCREEN)返回像素,所以我认为该值不受DPI设置的影响-而是。那么,有没有一种更安全的方法来找出真正的,未缩放的屏幕分辨率?
According to the MSDN, getSystemMetrics(SM_CXSCREEN) returns pixels, so I thought this value wouldn't be affected by the DPI settings - but it is. So is there a safer way to find out the true, unscaled screen resolution?
推荐答案
程序必须告诉操作系统它当您超过125%时,DPI可以识别真正的分辨率。最好使用清单来完成,如此。
A program must tell the operating system that it is DPI-aware to get the true resolution when you go past 125%. That's best done with a manifest, as explained in this MSDN Library article.
这篇关于GetSystemMetrics()为SM_CXSCREEN返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!