获取系统的DPI设置

在Measure控件的宽度的时候,有时候需要考虑DPI的缩放,一个简单的函数调用就可以解决:GetDeviceCaps()会返回当前的DPI值,一般是96,Win7下面设置为125%,就变成了120。


// Use "A" to measure the hint list width. "M" is too long and displayText
// can be too short, see DID#1482150. And we also need to take DPI into
// consider.
m_textWidthMax = dc.GetTextExtent(displayText, displayText.GetLength()).cx + 2;
m_textWidthMax *= (dc.GetDeviceCaps(LOGPIXELSX)/96);

原文地址:https://www.cnblogs.com/puncha/p/3876967.html