【问题标题】:GetSystemMetrics return wrong value for my screenGetSystemMetrics 为我的屏幕返回错误值
【发布时间】:2016-10-03 10:54:14
【问题描述】:

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

我有 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)还是我做错了什么?

【问题讨论】:

标签: c++ c windows


【解决方案1】:

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

请看GetSystemMetrics() returns wrong value for SM_CXSCREEN

还有SetProcessDPIAwareSetProcessDpiAwareness API

【讨论】:

    猜你喜欢
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多