基于WINDOWS 32API封装的显示器类: (1) 头文件
1/************************************************************************
2 @file monitor.h
3 * Author: qinqing
4 * Date: 2009-12-2
5************************************************************************/
6
7#ifndef _MONITOR_H
8
9#if WINVER < 0x0500
10#include <multimon.h>
11#endif
12#include "..\common\tstring.h"
13#include "..\common\macro.h"
14#include <map>
15
16/**
17 @brief 显示器类
18 @class CMonitor
19*/
20class CMonitor
21{
22 friend class CMonitorManager;
23public:
24 void GetMonitorRect(RECT& rect) const;
25 void GetWorkAreaRect(RECT& rect) const;
26 DWORD GetPixelWidth() const;
27 DWORD GetPixelHeight() const;
28 DWORD GetBitsPerPixel() const;
29 DWORD GetMonitorLeft() const;
30 DWORD GetMonitorTop() const;
31 DWORD GetDisplayFrequency() const;
32 bool IsPrimaryMonitor() const;
33 tstring GetName() const { return m_strName; }
34 DWORD GetIndex() const { return m_dwIndex; }
35 operator HMONITOR() const { return m_hMonitor; }
36
37protected:
38 void CenterRectToMonitor(LPRECT lprc, bool bWorkArea= false) const;
39
40private:
41 CMonitor(HMONITOR hMonitor, DWORD dwIndex);
42
43private:
44 HMONITOR m_hMonitor; /**////< 显示器句柄
45 DWORD m_dwIndex; ///< 显示器索引
46 tstring m_strName; ///< 显示器名称
47};
48
49/**
50 @brief 显示器管理类
51 @class CMonitorManager
52 * 仅支持多屏独立显示模式(每个显示器分辨率是独立的),其它模式(大水平,大垂直,复制)暂不考虑
53*/
54class CMonitorManager
55{
56 SINGLETON_DECLARE(CMonitorManager) ///< 单件声明宏
57
58public:
59 DWORD GetCount();
60 CMonitor* GetMonitor(DWORD dwIndex);
61 CMonitor* GetPrimaryMonitor();
62 CMonitor* GetNearestMonitor(const RECT& rect);
63 CMonitor* GetNearestMonitor(const POINT& pt);
64 CMonitor* GetNearestMonitor(HWND hWnd);
65
66public:
67 static void GetVirtualDesktopRect(RECT& rect);
68 bool FullScreenWindow(HWND hWnd, bool bFullScreen, int iMonitorIndex = 0);
69 bool FullScreenWindow(HWND hWndFirst, HWND hWndSecond);
70 void CenterWindow(HWND hWnd, int iMonitorIndex = 0, bool bUseWorkArea = false);
71
72protected:
73 static BOOL CALLBACK AddMonitorsCallBack(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,
74 LPARAM dwData);
75
76private:
77 void CenterWindowToAll(RECT& rect, bool bUseWorkArea = false);
78 void UpdateMonitors();
79 CMonitor* FindMonitor(HMONITOR hMonitor);
80 void FreeMonitors();
81
82private:
83 struct WndInfo
84 {
85 WndInfo(lo
- 发表评论
-
- 最新评论 更多>>