枚举多显示器信息 EnumDisplayMonitors 应用
- UID
- 1066743
|
枚举多显示器信息 EnumDisplayMonitors 应用
class CMultiMonitorEnumerator
{
public:
int m_iMontorNumber;
typedef struct _tagVMonitorInfo_t
{
HMONITOR hMonitor; //显示器句柄
TCHAR szDevice[32]; //显示器名
RECT rcVirtual; //虚拟显示屏坐标
RECT rcMonitor; //物理显示坐标
RECT rcWork; //工作显示坐标
BOOL bPrimary; //主显示器?
_tagVMonitorInfo_t()
{
memset(this, 0, sizeof(*this));
}
}VMONITORINFO, *LPVMONITORINFO;
//显示器信息列表
VMONITORINFO m_MonitorInfoExArray[64];
protected:
//枚举显示器回调函数
static BOOL CALLBACK MonitorEnumProc(
HMONITOR hMonitor, // handle to display monitor
HDC hdcMonitor, // handle to monitor-appropriate device context
LPRECT lprcMonitor, // pointer to monitor intersection rectangle
LPARAM dwData // data passed from EnumDisplayMonitors
)
{
CMultiMonitorEnumerator *pThis = (CMultiMonitorEnumerator *)dwData;
//The rectangle coordinates are virtual-screen coordinates
if(lprcMonitor)
{
TRACE(_T("%p (l=%d t=%d r=%d b=%d)\n"),
hMonitor,
lprcMonitor->left, lprcMonitor->top,
lprcMonitor->right, lprcMonitor->bottom);
}
//GetMonitorInfo 获取显示器信息
MONITORINFOEX infoEx;
memset(&infoEx, 0, sizeof(infoEx));
infoEx.cbSize = sizeof(infoEx);
if(GetMonitorInfo(hMonitor, &infoEx))
{
TRACE(_T("%p [%s] %s rcMonitor(l=%d t=%d r=%d b=%d) rcWork(l=%d t=%d r=%d b=%d)\n"),
hMonitor,
infoEx.szDevice,
infoEx.dwFlags == MONITORINFOF_PRIMARY? _T("Primary"):_T("Slave"),
infoEx.rcMonitor.left, infoEx.rcMonitor.top, infoEx.rcMonitor.right, infoEx.rcMonitor.bottom,
infoEx.rcWork.left, infoEx.rcWork.top, infoEx.rcWork.right, infoEx.rcWork.bottom);
}
//保存显示器信息
if(pThis->m_iMontorNumber < _countof(pThis->m_MonitorInfoExArray) - 1)
{
VMONITORINFO *pInfo = &pThis->m_MonitorInfoExArray[pThis->m_iMontorNumber];
pInfo->hMonitor = hMonitor;
if(lprcMonitor)
{
pInfo->rcVirtual = *lprcMonitor;
}
pInfo->rcMonitor = infoEx.rcMonitor;
pInfo->rcWork = infoEx.rcWork;
pInfo->bPrimary = infoEx.dwFlags == MONITORINFOF_PRIMARY;
_tcscpy_s(pInfo->szDevice, infoEx.szDevice);
pThis->m_iMontorNumber++;
return TRUE; //continue the enumeration
}
return FALSE; //stop the enumeration
}
public:
CMultiMonitorEnumerator()
{
m_iMontorNumber = 0;
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)this);
}
}; |
|
|
|
|
|