繁体   English   中英

GetSystemMetrics返回我的屏幕错误的值

[英]GetSystemMetrics return wrong value for my screen

我有一个示例代码来获取像素的高度和宽度。 但是它为我的屏幕显示了错误的分辨率。

我有3840 x 2160。

但应用程序说:1920 x 1080。

码:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, int in, int in2)
{
    TCHAR szBuffer[1024];
    va_list pArgList;
    // The va_start macro (defined in STDARG.H) is usually equivalent to
    // pArgList = (char *) &szFormat + sizeof (szFormat) ;
    va_start(pArgList, szFormat);
    // The last argument to wvsprintf points to the arguments
    _vsntprintf_s(szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
    szFormat, pArgList);
    // The va_end macro just zeroes out pArgList for no good reason
    va_end(pArgList);
    return MessageBox(NULL, szBuffer, szCaption, 0);
}
int WINAPI WinMain(HINSTANCE hTnstance, HINSTANCE hPreVInStane,PSTR szCmdLine, int iCmdShow)
{
    int cxScreen=0, cyScreen=0;
    cxScreen = GetSystemMetrics(SM_CXSCREEN);
    cyScreen = GetSystemMetrics(SM_CYSCREEN);
    MessageBoxPrintf(TEXT("ScrnSize"), TEXT("Wide %i High %i"), cxScreen, cyScreen);
    return 0;
}  

这个功能是过时的(GetSystemMetrics)还是我做错了什么?

该问题是由于您的显示DPI /缩放设置

请参阅GetSystemMetrics()为SM_CXSCREEN返回错误的值

还有SetProcessDPIAwareSetProcessDpiAwareness API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM