source: trunk/Utilities/MonitorInformation/MainDialog.h @ 288

Last change on this file since 288 was 288, checked in by roman, 10 years ago
File size: 6.3 KB
Line 
1////////////////////////////////////////////////////////////
2// MainDialog.h
3//
4// Copyright (C) Alax.Info, 2006-2008
5// http://alax.info
6//
7// A permission to use the source code is granted as long as reference to
8// source website http://alax.info is retained.
9//
10// Created by Roman Ryltsov roman@alax.info
11//
12// $Id: MainDialog.h 219 2010-08-20 12:57:35Z alax $
13
14#pragma once
15
16#include <atlcoll.h>
17#include <atlcrack.h>
18#include <atlmisc.h>
19
20////////////////////////////////////////////////////////////
21// CMainDialog
22
23class CMainDialog : 
24        public CDialogImpl<CMainDialog>,
25        public CDialogResize<CMainDialog>
26{
27public:
28
29        enum { IDD = IDD_MAIN };
30
31BEGIN_MSG_MAP_EX(CMainDialog)
32        MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
33        CHAIN_MSG_MAP(CDialogResize<CMainDialog>)
34        MSG_WM_INITDIALOG(OnInitDialog)
35        COMMAND_ID_HANDLER_EX(IDOK, OnCommand)
36        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand)
37END_MSG_MAP()
38
39BEGIN_DLGRESIZE_MAP(CMainDialog)
40        DLGRESIZE_CONTROL(IDC_TEXT, DLSZ_SIZE_X | DLSZ_SIZE_Y)
41        DLGRESIZE_CONTROL(IDC_MODE, DLSZ_MOVE_Y)
42        DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_X | DLSZ_MOVE_Y)
43END_DLGRESIZE_MAP()
44
45public:
46        typedef MONITORINFOEX MYMONITORINFO; // To switch between MONITORINFO and MONITORINFOEX
47
48        ////////////////////////////////////////////////////////
49        // CMonitorInformation
50
51        class CMonitorInformation
52        {
53        public:
54                MYMONITORINFO m_MonitorInformation;
55
56        public:
57        // CMonitorInformation
58                CMonitorInformation() throw()
59                {
60                }
61                CMonitorInformation(const CMonitorInformation& MonitorInformation) throw() :
62                        m_MonitorInformation(MonitorInformation.m_MonitorInformation)
63                {
64                }
65                CMonitorInformation(const MYMONITORINFO& MonitorInformation) throw() :
66                        m_MonitorInformation(MonitorInformation)
67                {
68                }
69        };
70
71        ////////////////////////////////////////////////////////
72        // CMonitorInformationArray
73
74        class CMonitorInformationArray :
75                public CAtlArray<CMonitorInformation>
76        {
77        public:
78        // CMonitorInformationArray
79        };
80
81private:
82        CMonitorInformationArray m_MonitorInformationArray;
83        SIZE_T m_nMonitorIndex;
84        CString m_sText;
85        CEdit m_TextEdit;
86        CComboBox m_ModeComboBox;
87
88        BOOL EnumerateMonitors(HMONITOR hMonitor, CDCHandle MonitorDc, const CRect& MonitorPosition)
89        {
90                m_sText.AppendFormat(_T("Monitor %d at (%d, %d) - (%d, %d):\r\n"), m_nMonitorIndex, MonitorPosition.left, MonitorPosition.top, MonitorPosition.right, MonitorPosition.bottom);
91                MYMONITORINFO MonitorInformation;
92                ZeroMemory(&MonitorInformation, sizeof MonitorInformation);
93                MonitorInformation.cbSize = sizeof MonitorInformation;
94                ATLVERIFY(GetMonitorInfo(hMonitor, &MonitorInformation));
95                m_sText.AppendFormat(_T("  Coordinates (rcMonitor): (%d, %d) - (%d, %d)\r\n"), MonitorInformation.rcMonitor.left, MonitorInformation.rcMonitor.top, MonitorInformation.rcMonitor.right, MonitorInformation.rcMonitor.bottom);
96                m_sText.AppendFormat(_T("  Work Area (rcWork): (%d, %d) - (%d, %d)\r\n"), MonitorInformation.rcWork.left, MonitorInformation.rcWork.top, MonitorInformation.rcWork.right, MonitorInformation.rcWork.bottom);
97                m_sText.AppendFormat(_T("  Flags (dwFlags): 0x%x\r\n"), MonitorInformation.dwFlags);
98                __if_exists(MYMONITORINFO::szDevice)
99                {
100                        m_sText.AppendFormat(_T("  Device Name (szDevice): %s\r\n"), MonitorInformation.szDevice);
101                }
102                m_sText.Append(_T("\r\n"));
103                ATLVERIFY(m_MonitorInformationArray.Add(MonitorInformation) == m_nMonitorIndex);
104                m_nMonitorIndex++;
105                return TRUE;
106        }
107        static BOOL CALLBACK EnumerateMonitors(HMONITOR hMonitor, HDC hMonitorDc, RECT* pMonitorPosition, LPARAM nParameter) throw()
108        {
109                return ((CMainDialog*) nParameter)->EnumerateMonitors(hMonitor, hMonitorDc, *pMonitorPosition);
110        }
111
112public:
113// CMainDialog
114        VOID Initialize()
115        {
116                m_MonitorInformationArray.RemoveAll();
117                m_nMonitorIndex = 0;
118                m_sText.Empty();
119                m_sText.Append(_T("System Metrics:\r\n"));
120                m_sText.AppendFormat(_T("  SM_XVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_XVIRTUALSCREEN));
121                m_sText.AppendFormat(_T("  SM_YVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_YVIRTUALSCREEN));
122                m_sText.AppendFormat(_T("  SM_CXVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_CXVIRTUALSCREEN));
123                m_sText.AppendFormat(_T("  SM_CYVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_CYVIRTUALSCREEN));
124                m_sText.AppendFormat(_T("  SM_CMONITORS: %d\r\n"), GetSystemMetrics(SM_CMONITORS));
125                m_sText.AppendFormat(_T("  SM_SAMEDISPLAYFORMAT: %d\r\n"), GetSystemMetrics(SM_SAMEDISPLAYFORMAT));
126                m_sText.Append(_T("\r\n"));
127                EnumDisplayMonitors(NULL, NULL, EnumerateMonitors, (LPARAM) this);
128        }
129
130// Window message handlers
131        LRESULT OnInitDialog(HWND, LPARAM)
132        {
133                Initialize();
134                DlgResize_Init(FALSE);
135                m_TextEdit = GetDlgItem(IDC_TEXT);
136                m_TextEdit.SetWindowText(m_sText);
137                m_ModeComboBox = GetDlgItem(IDC_MODE);
138                for(SIZE_T nMonitorIndex = 0; nMonitorIndex < m_MonitorInformationArray.GetCount(); nMonitorIndex++)
139                {
140                        const CMonitorInformation& MonitorInformation = m_MonitorInformationArray[nMonitorIndex];
141                        CString sText;
142                        sText.Format(_T("Maximize to Monitor #%d, (%d, %d) - (%d, %d)"), nMonitorIndex + 1, MonitorInformation.m_MonitorInformation.rcMonitor.left, MonitorInformation.m_MonitorInformation.rcMonitor.top, MonitorInformation.m_MonitorInformation.rcMonitor.right, MonitorInformation.m_MonitorInformation.rcMonitor.bottom);
143                        m_ModeComboBox.SetItemData(m_ModeComboBox.AddString(sText), (DWORD_PTR) nMonitorIndex);
144                }
145                m_ModeComboBox.SetCurSel(0);
146                SetIcon(AtlLoadIconImage(IDR_MAINFRAME, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR), TRUE);
147                //SetIcon(AtlLoadIconImage(IDR_MAINFRAME, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR), FALSE);
148                ATLVERIFY(CenterWindow());
149                return TRUE;
150        }
151        LRESULT OnGetMinMaxInfo(MINMAXINFO* pMinMaxInfo)
152        {
153                ATLASSERT(pMinMaxInfo);
154                const CMonitorInformation& MonitorInformation = m_MonitorInformationArray[m_ModeComboBox.GetItemData(m_ModeComboBox.GetCurSel())];
155                reinterpret_cast<CPoint&>(pMinMaxInfo->ptMaxPosition) = reinterpret_cast<const CRect&>(MonitorInformation.m_MonitorInformation.rcMonitor).TopLeft();
156                reinterpret_cast<CPoint&>(pMinMaxInfo->ptMaxTrackSize) = reinterpret_cast<const CRect&>(MonitorInformation.m_MonitorInformation.rcMonitor).Size();
157                return 0;
158        }
159        LRESULT OnCommand(UINT, INT nIdentifier, HWND)
160        {
161                ATLVERIFY(EndDialog(nIdentifier));
162                return 0;
163        }
164};
Note: See TracBrowser for help on using the repository browser.