Using plain C, (not C++ / C# / Objective-C) how do I get the screen resolution in Windows?
My compiler is MingW (not sure if relevant). All solutions I have found online are for C++ or some other C variant.
Use GetSystemMetrics()
DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
You'll have to use the Windows API by including windows.h
in your code. MingW may already come with this header file.
#include <windows.h>
void GetMonitorResolution(int *horizontal, int *vertical) {
*height = GetSystemMetrics(SM_CYSCREEN);
*width = GetSystemMetrics(SM_CXSCREEN);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With