EnumDisplayMonitors样例
时间: 2024-05-01 09:16:17 浏览: 107
Enum的实例
以下是一个使用EnumDisplayMonitors函数的样例,它可以列出所有可用的显示器并输出它们的设备名称和分辨率:
```C++
#include <Windows.h>
#include <iostream>
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(monitorInfo);
if (GetMonitorInfo(hMonitor, &monitorInfo))
{
std::cout << "Device name: " << monitorInfo.szDevice << std::endl;
std::cout << "Resolution: " << monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left << "x" << monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top << std::endl;
}
return TRUE;
}
int main()
{
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, NULL);
return 0;
}
```
输出:
```
Device name: \\.\DISPLAY1
Resolution: 1920x1080
Device name: \\.\DISPLAY2
Resolution: 1280x1024
```
阅读全文