旧VC项目dpiAware支持
起因
工作原因,需要维护一款VS2008 SP1开发的MFC项目,
发现WIN10高分辨率下显示模糊,不考虑升级VC版本情况下尝试解决
尝试
新版本VC中Manifest Tool
>Input and Output
内有一项dpiAware
,应该是加了对应清单项,
尝试添加一下内容到hdpi.xml
并Manifest Tool
>Input and Output
>Additional Manifest Files
添加hdpi.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
报错 manifest authoring warning 81010002: Unrecognized Element "application" in namespace "urn:schemas-microsoft-com:asm.v3".
参考https://social.msdn.microsoft.com/Forums/vstudio/en-US/ab815aa4-bd4d-4ab2-8826-fa20b0816372/how-to-make-application-to-fit-dpi-setting
应该是mt.ex版本问题
解决
利用win8.1后新API,完美解决
SetProcessDpiAwareness
示例代码,兼容MinGW、VC,不区分C/C++
#define UNICODE
#include <windows.h>
static void _DpiNohelp()
{
typedef HRESULT (WINAPI *FSetProcessDpiAwareness)(int value);
HMODULE m = NULL; FARPROC proc = NULL;
if(m = LoadLibrary(L"shcore.dll")) {
if(proc = GetProcAddress(m, "SetProcessDpiAwareness"))
((FSetProcessDpiAwareness)proc)(2);
FreeLibrary(m);
}
}
int main() {
_DpiNohelp();
MessageBox(0,0,0,0);
}
欢迎各位转载,但必须在文章页面中给出作者和原文链接!