现在的屏幕分辨率都比较高,为了使屏幕字体不至于太小,通常在 Win10 的显示设置里面设为放大 125% 或 150% 或更大,这样就会导致像素实际上被放大了。
如果你的程序不希望受系统缩放设置影响,你需要使用一个新的 API 函数:SetProcessDpiAwareness
void setupDPIAwareness()
{
typedef HRESULT *(__stdcall *SetProcessDpiAwarenessFunc)(PROCESS_DPI_AWARENESS);
HMODULE shCore = LoadLibraryA("Shcore.dll");
if (shCore)
{
SetProcessDpiAwarenessFunc setProcessDpiAwareness =
(SetProcessDpiAwarenessFunc)GetProcAddress(shCore, "SetProcessDpiAwareness");
if (setProcessDpiAwareness != nullptr)
{
setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
}
FreeLibrary(shCore);
}
}