Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Get Screen Resolution in C

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.

like image 703
Jimmay Avatar asked Sep 18 '25 05:09

Jimmay


2 Answers

Use GetSystemMetrics()

DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
like image 183
user2422531 Avatar answered Sep 20 '25 20:09

user2422531


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);
}
like image 21
Pranav Negandhi Avatar answered Sep 20 '25 22:09

Pranav Negandhi