1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Alax.Info, 2006-2015 |
---|
3 | // http://alax.info |
---|
4 | // |
---|
5 | // A permission to use the source code is granted as long as reference to |
---|
6 | // source website http://alax.info is retained. |
---|
7 | // |
---|
8 | // Created by Roman Ryltsov roman@alax.info |
---|
9 | |
---|
10 | #pragma once |
---|
11 | |
---|
12 | #include <atlcoll.h> |
---|
13 | #include <atlcrack.h> |
---|
14 | #include <atlmisc.h> |
---|
15 | |
---|
16 | //////////////////////////////////////////////////////////// |
---|
17 | // CMainDialog |
---|
18 | |
---|
19 | class CMainDialog : |
---|
20 | public CDialogImpl<CMainDialog>, |
---|
21 | public CDialogResize<CMainDialog> |
---|
22 | { |
---|
23 | public: |
---|
24 | |
---|
25 | enum { IDD = IDD_MAIN }; |
---|
26 | |
---|
27 | BEGIN_MSG_MAP_EX(CMainDialog) |
---|
28 | MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) |
---|
29 | CHAIN_MSG_MAP(CDialogResize<CMainDialog>) |
---|
30 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
31 | COMMAND_ID_HANDLER_EX(IDOK, OnCommand) |
---|
32 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand) |
---|
33 | END_MSG_MAP() |
---|
34 | |
---|
35 | BEGIN_DLGRESIZE_MAP(CMainDialog) |
---|
36 | DLGRESIZE_CONTROL(IDC_TEXT, DLSZ_SIZE_X | DLSZ_SIZE_Y) |
---|
37 | DLGRESIZE_CONTROL(IDC_MODE, DLSZ_MOVE_Y) |
---|
38 | DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_X | DLSZ_MOVE_Y) |
---|
39 | END_DLGRESIZE_MAP() |
---|
40 | |
---|
41 | public: |
---|
42 | typedef MONITORINFOEX MYMONITORINFO; // To switch between MONITORINFO and MONITORINFOEX |
---|
43 | |
---|
44 | //////////////////////////////////////////////////////// |
---|
45 | // CMonitorInformation |
---|
46 | |
---|
47 | class CMonitorInformation |
---|
48 | { |
---|
49 | public: |
---|
50 | MYMONITORINFO m_MonitorInformation; |
---|
51 | |
---|
52 | public: |
---|
53 | // CMonitorInformation |
---|
54 | CMonitorInformation() |
---|
55 | { |
---|
56 | } |
---|
57 | CMonitorInformation(const CMonitorInformation& MonitorInformation) : |
---|
58 | m_MonitorInformation(MonitorInformation.m_MonitorInformation) |
---|
59 | { |
---|
60 | } |
---|
61 | CMonitorInformation(const MYMONITORINFO& MonitorInformation) : |
---|
62 | m_MonitorInformation(MonitorInformation) |
---|
63 | { |
---|
64 | } |
---|
65 | }; |
---|
66 | |
---|
67 | //////////////////////////////////////////////////////// |
---|
68 | // CMonitorInformationArray |
---|
69 | |
---|
70 | class CMonitorInformationArray : |
---|
71 | public CAtlArray<CMonitorInformation> |
---|
72 | { |
---|
73 | public: |
---|
74 | // CMonitorInformationArray |
---|
75 | }; |
---|
76 | |
---|
77 | private: |
---|
78 | CMonitorInformationArray m_MonitorInformationArray; |
---|
79 | SIZE_T m_nMonitorIndex; |
---|
80 | CString m_sText; |
---|
81 | CEdit m_TextEdit; |
---|
82 | CComboBox m_ModeComboBox; |
---|
83 | |
---|
84 | BOOL EnumerateMonitors(HMONITOR hMonitor, CDCHandle MonitorDc, const CRect& MonitorPosition) |
---|
85 | { |
---|
86 | m_sText.AppendFormat(_T("Monitor %d at (%d, %d) - (%d, %d):") _T("\r\n"), m_nMonitorIndex, MonitorPosition.left, MonitorPosition.top, MonitorPosition.right, MonitorPosition.bottom); |
---|
87 | MYMONITORINFO MonitorInformation; |
---|
88 | ZeroMemory(&MonitorInformation, sizeof MonitorInformation); |
---|
89 | MonitorInformation.cbSize = sizeof MonitorInformation; |
---|
90 | ATLVERIFY(GetMonitorInfo(hMonitor, &MonitorInformation)); |
---|
91 | m_sText.AppendFormat(_T(" Coordinates (rcMonitor): (%d, %d) - (%d, %d)") _T("\r\n"), MonitorInformation.rcMonitor.left, MonitorInformation.rcMonitor.top, MonitorInformation.rcMonitor.right, MonitorInformation.rcMonitor.bottom); |
---|
92 | m_sText.AppendFormat(_T(" Work Area (rcWork): (%d, %d) - (%d, %d)") _T("\r\n"), MonitorInformation.rcWork.left, MonitorInformation.rcWork.top, MonitorInformation.rcWork.right, MonitorInformation.rcWork.bottom); |
---|
93 | m_sText.AppendFormat(_T(" Flags (dwFlags): 0x%X") _T("\r\n"), MonitorInformation.dwFlags); |
---|
94 | __if_exists(MYMONITORINFO::szDevice) |
---|
95 | { |
---|
96 | m_sText.AppendFormat(_T(" Device Name (szDevice): %s") _T("\r\n"), MonitorInformation.szDevice); |
---|
97 | } |
---|
98 | ATLASSERT(!MonitorDc); |
---|
99 | //m_sText.Append(_T(" Capabilities:") _T("\r\n")); |
---|
100 | //m_sText.AppendFormat(_T(" VREFRESH: %d") _T("\r\n"), MonitorDc.GetDeviceCaps(VREFRESH)); |
---|
101 | m_sText.Append(_T("\r\n")); |
---|
102 | ATLVERIFY(m_MonitorInformationArray.Add(MonitorInformation) == m_nMonitorIndex); |
---|
103 | m_nMonitorIndex++; |
---|
104 | return TRUE; |
---|
105 | } |
---|
106 | static BOOL CALLBACK EnumerateMonitors(HMONITOR hMonitor, HDC hMonitorDc, RECT* pMonitorPosition, LPARAM nParameter) |
---|
107 | { |
---|
108 | return ((CMainDialog*) nParameter)->EnumerateMonitors(hMonitor, hMonitorDc, *pMonitorPosition); |
---|
109 | } |
---|
110 | |
---|
111 | public: |
---|
112 | // CMainDialog |
---|
113 | VOID Initialize() |
---|
114 | { |
---|
115 | // NOTE: EnumDisplayDevices vs EnumDisplayMonitors http://stackoverflow.com/questions/27042576/enumdisplaydevices-vs-enumdisplaymonitors |
---|
116 | m_MonitorInformationArray.RemoveAll(); |
---|
117 | m_nMonitorIndex = 0; |
---|
118 | m_sText.Empty(); |
---|
119 | #pragma region System Metrics |
---|
120 | m_sText.Append(_T("System Metrics:\r\n")); |
---|
121 | m_sText.AppendFormat(_T(" SM_XVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_XVIRTUALSCREEN)); |
---|
122 | m_sText.AppendFormat(_T(" SM_YVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_YVIRTUALSCREEN)); |
---|
123 | m_sText.AppendFormat(_T(" SM_CXVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_CXVIRTUALSCREEN)); |
---|
124 | m_sText.AppendFormat(_T(" SM_CYVIRTUALSCREEN: %d\r\n"), GetSystemMetrics(SM_CYVIRTUALSCREEN)); |
---|
125 | m_sText.AppendFormat(_T(" SM_CMONITORS: %d\r\n"), GetSystemMetrics(SM_CMONITORS)); |
---|
126 | m_sText.AppendFormat(_T(" SM_SAMEDISPLAYFORMAT: %d\r\n"), GetSystemMetrics(SM_SAMEDISPLAYFORMAT)); |
---|
127 | m_sText.Append(_T("\r\n")); |
---|
128 | #pragma endregion |
---|
129 | EnumDisplayMonitors(NULL, NULL, EnumerateMonitors, (LPARAM) this); |
---|
130 | #pragma region Display Devices |
---|
131 | m_sText.Append(_T("Display Devices:") _T("\r\n")); |
---|
132 | m_sText.Append(_T("\r\n")); |
---|
133 | for(DWORD nIndex = 0; ; nIndex++) |
---|
134 | { |
---|
135 | DISPLAY_DEVICE DisplayDevice = { sizeof DisplayDevice }; |
---|
136 | if(!EnumDisplayDevices(NULL, nIndex, &DisplayDevice, EDD_GET_DEVICE_INTERFACE_NAME)) |
---|
137 | break; |
---|
138 | m_sText.AppendFormat(_T(" DeviceName: %s") _T("\r\n"), DisplayDevice.DeviceName); |
---|
139 | m_sText.AppendFormat(_T(" DeviceString: %s") _T("\r\n"), DisplayDevice.DeviceString); |
---|
140 | CString sStateFlags; |
---|
141 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE) |
---|
142 | sStateFlags.Append(_T("DISPLAY_DEVICE_ACTIVE | ")); |
---|
143 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) |
---|
144 | sStateFlags.Append(_T("DISPLAY_DEVICE_MIRRORING_DRIVER | ")); |
---|
145 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_MODESPRUNED) |
---|
146 | sStateFlags.Append(_T("DISPLAY_DEVICE_MODESPRUNED | ")); |
---|
147 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) |
---|
148 | sStateFlags.Append(_T("DISPLAY_DEVICE_PRIMARY_DEVICE | ")); |
---|
149 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_REMOVABLE) |
---|
150 | sStateFlags.Append(_T("DISPLAY_DEVICE_REMOVABLE | ")); |
---|
151 | if(DisplayDevice.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE) |
---|
152 | sStateFlags.Append(_T("DISPLAY_DEVICE_VGA_COMPATIBLE | ")); |
---|
153 | sStateFlags.TrimRight(_T(" |")); |
---|
154 | m_sText.AppendFormat(_T(" StateFlags: 0x%X %s") _T("\r\n"), DisplayDevice.StateFlags, sStateFlags); |
---|
155 | if(_tcslen(DisplayDevice.DeviceID)) |
---|
156 | m_sText.AppendFormat(_T(" DeviceID: %s") _T("\r\n"), DisplayDevice.DeviceID); |
---|
157 | m_sText.AppendFormat(_T(" DeviceKey: %s") _T("\r\n"), DisplayDevice.DeviceKey); |
---|
158 | m_sText.Append(_T("\r\n")); |
---|
159 | #pragma region |
---|
160 | m_sText.Append(_T(" Settings (Modes):") _T("\r\n")); |
---|
161 | for(DWORD nIndex = (DWORD) -1; ; nIndex++) |
---|
162 | { |
---|
163 | ATLASSERT(ENUM_CURRENT_SETTINGS == (DWORD) -1); |
---|
164 | static const SIZE_T g_nDeviceModeCapacity = 4 << 10; |
---|
165 | CTempBuffer<DEVMODE, g_nDeviceModeCapacity> pDeviceMode(g_nDeviceModeCapacity); |
---|
166 | DEVMODE& DeviceMode = *pDeviceMode; |
---|
167 | ZeroMemory(&DeviceMode, g_nDeviceModeCapacity); |
---|
168 | pDeviceMode->dmSize = sizeof DeviceMode; |
---|
169 | pDeviceMode->dmDriverExtra = g_nDeviceModeCapacity - sizeof DeviceMode; |
---|
170 | if(!EnumDisplaySettingsEx(DisplayDevice.DeviceName, nIndex, &DeviceMode, 0)) |
---|
171 | break; |
---|
172 | if(nIndex == ENUM_CURRENT_SETTINGS) |
---|
173 | m_sText.AppendFormat(_T(" %s:") _T("\r\n"), _T("Current")); |
---|
174 | else |
---|
175 | m_sText.AppendFormat(_T(" Mode %d:") _T("\r\n"), nIndex); |
---|
176 | m_sText.AppendFormat(_T(" dmBitsPerPel: %d") _T("\r\n"), DeviceMode.dmBitsPerPel); |
---|
177 | m_sText.AppendFormat(_T(" dmPelsWidth: %d") _T("\r\n"), DeviceMode.dmPelsWidth); |
---|
178 | m_sText.AppendFormat(_T(" dmPelsHeight: %d") _T("\r\n"), DeviceMode.dmPelsHeight); |
---|
179 | m_sText.AppendFormat(_T(" dmDisplayFlags: 0x%X") _T("\r\n"), DeviceMode.dmDisplayFlags); |
---|
180 | m_sText.AppendFormat(_T(" dmDisplayFrequency: %d") _T("\r\n"), DeviceMode.dmDisplayFrequency); |
---|
181 | m_sText.AppendFormat(_T(" dmPosition: %d") _T("\r\n"), DeviceMode.dmPosition); |
---|
182 | m_sText.AppendFormat(_T(" dmDisplayOrientation: %d") _T("\r\n"), DeviceMode.dmDisplayOrientation); |
---|
183 | } |
---|
184 | #pragma endregion |
---|
185 | m_sText.Append(_T("\r\n")); |
---|
186 | } |
---|
187 | #pragma endregion |
---|
188 | } |
---|
189 | |
---|
190 | // Window message handlers |
---|
191 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
192 | { |
---|
193 | Initialize(); |
---|
194 | DlgResize_Init(FALSE); |
---|
195 | m_TextEdit = GetDlgItem(IDC_TEXT); |
---|
196 | m_TextEdit.SetWindowText(m_sText); |
---|
197 | m_ModeComboBox = GetDlgItem(IDC_MODE); |
---|
198 | for(SIZE_T nMonitorIndex = 0; nMonitorIndex < m_MonitorInformationArray.GetCount(); nMonitorIndex++) |
---|
199 | { |
---|
200 | const CMonitorInformation& MonitorInformation = m_MonitorInformationArray[nMonitorIndex]; |
---|
201 | CString sText; |
---|
202 | 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); |
---|
203 | m_ModeComboBox.SetItemData(m_ModeComboBox.AddString(sText), (DWORD_PTR) nMonitorIndex); |
---|
204 | } |
---|
205 | m_ModeComboBox.SetCurSel(0); |
---|
206 | SetIcon(AtlLoadIconImage(IDR_MAINFRAME, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR), TRUE); |
---|
207 | //SetIcon(AtlLoadIconImage(IDR_MAINFRAME, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR), FALSE); |
---|
208 | ATLVERIFY(CenterWindow()); |
---|
209 | return TRUE; |
---|
210 | } |
---|
211 | LRESULT OnGetMinMaxInfo(MINMAXINFO* pMinMaxInfo) |
---|
212 | { |
---|
213 | ATLASSERT(pMinMaxInfo); |
---|
214 | const CMonitorInformation& MonitorInformation = m_MonitorInformationArray[m_ModeComboBox.GetItemData(m_ModeComboBox.GetCurSel())]; |
---|
215 | reinterpret_cast<CPoint&>(pMinMaxInfo->ptMaxPosition) = reinterpret_cast<const CRect&>(MonitorInformation.m_MonitorInformation.rcMonitor).TopLeft(); |
---|
216 | reinterpret_cast<CPoint&>(pMinMaxInfo->ptMaxTrackSize) = reinterpret_cast<const CRect&>(MonitorInformation.m_MonitorInformation.rcMonitor).Size(); |
---|
217 | return 0; |
---|
218 | } |
---|
219 | LRESULT OnCommand(UINT, INT nIdentifier, HWND) |
---|
220 | { |
---|
221 | ATLVERIFY(EndDialog(nIdentifier)); |
---|
222 | return 0; |
---|
223 | } |
---|
224 | }; |
---|