C++获取DPI值

C++获取DPI值,第1张

win10/win11 获取系统DPI 源码

 

#include
#include
#include
#pragma comment(lib, "Shcore.lib")

using namespace std;

int main()
{
    HWND hWnd = ::GetDesktopWindow();
    HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);

    UINT dpiX = 0, dpiY = 0;

    GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
    dpiX = dpiX * 100 / 96;
    dpiY = dpiY * 100 / 96;

    cout <<"dpi "<< dpiX << "%" << endl;
    system("pause");
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1499304.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-25
下一篇 2022-06-25

发表评论

登录后才能评论

评论列表(0条)

保存