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 display class
18 @ class CMonitor
19 */
20 class CMonitor
21 {
22 friend class CMonitorManager;
23 public:
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
37 protected:
38 void CenterRectToMonitor (LPRECT lprc, bool bWorkArea = false) const;
39
40 private:
41 CMonitor (HMONITOR hMonitor, DWORD dwIndex );
42
43 private:
44 HMONITOR m_hMonitor;/*** /// <display handle
45 DWORD m_dwIndex; // <display Index
46 tstring m_strName; // <display name
47 };
48
49 /**
50 @ brief display management class
51 @ class CMonitorManager
52 * only multi-screen Independent display mode is supported (each display resolution is independent). Other modes (large horizontal, large vertical, and replication) are not considered for the moment.
53 */
54 class CMonitorManager
55 {
56 SINGLETON_DECLARE (CMonitorManager) // <single-piece acoustic macro
57
58 public:
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
66 public:
67 static void getvirtual1_toprect (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
72 protected:
73 static bool callback AddMonitorsCallBack (HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor,
74 LPARAM dwData );
75
76 private:
77 void CenterWindowToAll (RECT & rect, bool bUseWorkArea = false );
78 void UpdateMonitors ();
79 CMonitor * FindMonitor (HMONITOR hMonitor );
80 void FreeMonitors ();
81
82 private:
83 struct WndInfo
84 {
85 WndInfo (long lStyle, long lExStyle, RECT rcWnd, bool bFull ):
86 _ lStyle (lStyle), _ lExStyle (lExStyle), _ rcWnd (rcWnd), _ bFull (bFull ){}
87 WndInfo (){};
88 long _ lStyle;/** // <normal style
89 long _ lExStyle; // <extended Style
90 RECT _ rcWnd; // <rectangle
91 bool _ bFull; // <whether full screen is Enabled: true Yes, false No
92 };
93 std: vector <CMonitor *> m_vec_monitor; // <save all the displays of the current system
94 std: map <HWND, WndInfo> m_map_wnd; // <save the status of the restore window
95 };
96
97 # endif