Niklas
Niklas

Reputation: 1853

GetSystemMetrics return wrong value for my screen

I have a sample code to get the hight and width in pixels. But it shows the wrong resolution for my screen.

I have 3840 x 2160.

But the application says: 1920 x 1080.

Code:

#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;
}  

Is this funtion outdated (GetSystemMetrics) or im i doing something wrong?

Upvotes: 0

Views: 1879

Answers (1)

Chajnik-U
Chajnik-U

Reputation: 521

The issue is due to your display DPI/scailing settings

Please see GetSystemMetrics() returns wrong value for SM_CXSCREEN

And also SetProcessDPIAware and SetProcessDpiAwareness API

Upvotes: 2

Related Questions