2013-07-06 2 views
2

일반 C (C++/C#/Objective-C 아님)를 사용하면 Windows에서 화면 해상도를 어떻게 얻을 수 있습니까?Windows C에서 화면 해상도 가져 오기

제 컴파일러는 MingW입니다 (관련이 있는지 확실하지 않음). 온라인에서 찾은 모든 솔루션은 C++ 또는 다른 C 변형입니다.

답변

5

사용은 GetSystemMetrics()

DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN); 
DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN); 
+0

작업, 따 '아주 많이. – Jimmay

0

은 귀하의 질문은 이미 답했습니다 How to get the Monitor Screen Resolution from a hWnd?.

HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); 
MONITORINFO info; 
info.cbSize = sizeof(MONITORINFO); 
GetMonitorInfo(monitor, &info); 
int monitor_width = info.rcMonitor.right - info.rcMonitor.left; 
int monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; 
+0

MONITOR_DEFAULTTONEAREST가 정의되지 않았습니다. – Jimmay

+0

@Jimmay는 winuser.h를 열고 거기에서 모든 가능한 단지 #ifdef와 뒤에 숨겨져 있다면 그것을보고 검색 할 수 있습니다. – chris

0

당신은 당신의 코드에서 windows.h를 포함하여 Windows API를 사용해야합니다. MingW에는 이미이 헤더 파일이있을 수 있습니다.

#include <windows.h> 

void GetMonitorResolution(int *horizontal, int *vertical) { 
    *height = GetSystemMetrics(SM_CYSCREEN); 
    *width = GetSystemMetrics(SM_CXSCREEN); 
}