WIN32 API程式設計--列舉系統顯示器

weixin_34391854發表於2019-01-07

#include <conio.h>
#include <stdio.h>
#include <windows.h>

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,LPARAM dwData)
{
 MONITORINFOEX mi;
 mi.cbSize=sizeof(MONITORINFOEX);
 GetMonitorInfo(hMonitor,&mi);
 printf("Device name:%s\t",mi.szDevice);
 if(mi.dwFlags==MONITORINFOF_PRIMARY) printf("Primary monitor!\n");
 else printf("\n");
 printf("Monitor rectangle:(%d,%d,%d,%d)\n",mi.rcMonitor.left,mi.rcMonitor.top,mi.rcMonitor.right,mi.rcMonitor.bottom);
 printf("Work rectangle:(%d,%d,%d,%d)\n",mi.rcWork.left,mi.rcWork.top,mi.rcWork.right,mi.rcWork.bottom);
 return true;
}

int main(void)
{
 EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,NULL);
 getch();
 return 0;
}

相關文章