Windows在C中获得屏幕分辨率 使用普通C++,(不是C+++C/Objy-C)如何在Windows中获得屏幕分辨率?< /P>

Windows在C中获得屏幕分辨率 使用普通C++,(不是C+++C/Objy-C)如何在Windows中获得屏幕分辨率?< /P>,c,windows,mingw,screen-resolution,C,Windows,Mingw,Screen Resolution,我的编译器是MingW(不确定是否相关)。我在网上找到的所有解决方案都是C++或其他C变体。< P>使用 您的问题已得到回答: 您必须通过在代码中包含Windows.h来使用Windows API。MingW可能已经随此头文件提供 #include <windows.h> void GetMonitorResolution(int *horizontal, int *vertical) { *height = GetSystemMetrics(SM_CYSCREEN);

我的编译器是MingW(不确定是否相关)。我在网上找到的所有解决方案都是C++或其他C变体。

< P>使用


您的问题已得到回答:


您必须通过在代码中包含
Windows.h
来使用Windows API。MingW可能已经随此头文件提供

#include <windows.h>

void GetMonitorResolution(int *horizontal, int *vertical) {
    *height = GetSystemMetrics(SM_CYSCREEN);
    *width = GetSystemMetrics(SM_CXSCREEN);
}
#包括
void GetMonitorResolution(int*水平,int*垂直){
*高度=GetSystemMetrics(SM\u CYSCREEN);
*宽度=GetSystemMetrics(SM_CXSCREEN);
}

MONITOR\u DEFAULTTONEAREST未定义。@Jimmay,打开winuser.h并搜索它,看看它是否在那里,可能只是隐藏在一个#ifdef后面。
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;
#include <windows.h>

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