I have a problem with GetSystemMetrics(SM_CYSCREEN);
– the height this function returns is random each time I run the program but the width function, GetSystemMetrics(SM_CXSCREEN);
gives the correct value.
Here is my code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int MessageBoxPrintf(const wchar_t * szCaption, const wchar_t * szFormat, ...) {
wchar_t buffer[1024];
va_list v1;
va_start(v1, szFormat);
wchar_t* c = va_arg(v1, wchar_t*);
wsprintf(buffer, szFormat, c); //gives formated output to buffer
va_end(v1);
return MessageBox(NULL, buffer, szCaption, 0);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
int cxScreen, cyScreen;
cxScreen = GetSystemMetrics(SM_CXSCREEN);
cyScreen = GetSystemMetrics(SM_CYSCREEN);
MessageBoxPrintf(TEXT("ScreenRes"), TEXT("The screen is %i pixels wide by %i pixels high"), cxScreen, cyScreen);
return 0;
}
This program basically just is a Format string Message box with the WinAPI and C++.