0

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?

Niklas
  • 1,753
  • 4
  • 16
  • 35
  • 1
    These could be useful: https://social.msdn.microsoft.com/Forums/en-US/0a83bb55-31f3-4298-acbb-7ac1f48e3cad/why-getsystemmetricssmcxscreen-returns-1280-on-surface-pro-instead-of-1920?forum=winappswithnativecode and http://stackoverflow.com/questions/2630392/getsystemmetrics-returns-wrong-value-for-sm-cxscreen – enhzflep Oct 03 '16 at 10:57

1 Answers1

2

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

Community
  • 1
  • 1
Chajnik-U
  • 501
  • 4
  • 8