1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2011 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // $Id: Configuration.h 150 2012-11-23 14:44:52Z roman $ |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include <atlctrlx.h> |
---|
10 | #include <atlsplit.h> |
---|
11 | #include "rofiles.h" |
---|
12 | #include "AboutDialog.h" |
---|
13 | |
---|
14 | //////////////////////////////////////////////////////////// |
---|
15 | // CRegistrationPropertySheet |
---|
16 | |
---|
17 | class CRegistrationPropertySheet : |
---|
18 | public CPropertySheetT<CRegistrationPropertySheet> |
---|
19 | { |
---|
20 | public: |
---|
21 | |
---|
22 | BEGIN_MSG_MAP_EX(CRegistrationPropertySheet) |
---|
23 | CHAIN_MSG_MAP(CPropertySheet) |
---|
24 | MSG_WM_SYSCOMMAND(OnSysCommand) |
---|
25 | END_MSG_MAP() |
---|
26 | |
---|
27 | public: |
---|
28 | |
---|
29 | //////////////////////////////////////////////////////// |
---|
30 | // CRegistrationPropertyPage |
---|
31 | |
---|
32 | class CRegistrationPropertyPage : |
---|
33 | public CPropertyPageT<CRegistrationPropertyPage>, |
---|
34 | //public CDialogResize<CRegistrationPropertyPage>, |
---|
35 | public CWindowWithPrivateMessagesT<CRegistrationPropertyPage> |
---|
36 | { |
---|
37 | public: |
---|
38 | enum { IDD = IDD_REGISTRATION_REGISTRATION_PROPERTYPAGE }; |
---|
39 | |
---|
40 | BEGIN_MSG_MAP_EX(CRegistrationPropertyPage) |
---|
41 | CHAIN_MSG_MAP(CPropertyPage) |
---|
42 | //CHAIN_MSG_MAP(CDialogResize<CRegistrationPropertyPage>) |
---|
43 | CHAIN_MSG_MAP(CWindowWithPrivateMessages) |
---|
44 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
45 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_REGISTER, OnRegister) |
---|
46 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_UNREGISTER, OnUnregister) |
---|
47 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERREGISTER, OnUserRegister) |
---|
48 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER, OnUserUnregister) |
---|
49 | REFLECT_NOTIFICATIONS() |
---|
50 | END_MSG_MAP() |
---|
51 | |
---|
52 | private: |
---|
53 | CRegistrationPropertySheet& m_PropertySheet; |
---|
54 | CRoEdit m_StatusEdit; |
---|
55 | CRoEdit m_PathEdit; |
---|
56 | CButton m_RegisterButton; |
---|
57 | CButton m_UnregisterButton; |
---|
58 | CRoEdit m_UserStatusEdit; |
---|
59 | CRoEdit m_UserPathEdit; |
---|
60 | CButton m_UserRegisterButton; |
---|
61 | CButton m_UserUnregisterButton; |
---|
62 | //CRoIconStatic m_UserNoteStatic; |
---|
63 | CRoArrayT<CString> m_StatusArray; |
---|
64 | CPath m_sPath; |
---|
65 | CPath m_sUserPath; |
---|
66 | |
---|
67 | public: |
---|
68 | // CRegistrationPropertyPage |
---|
69 | CRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
70 | m_PropertySheet(*pPropertySheet) |
---|
71 | { |
---|
72 | } |
---|
73 | VOID UpdateControls() |
---|
74 | { |
---|
75 | _A(_pAtlModule); |
---|
76 | const CPath& sLocalPath = GetPath(); |
---|
77 | #pragma region System |
---|
78 | CPath sPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE); |
---|
79 | const BOOL bPathEmpty = _tcslen(sPath) == 0; |
---|
80 | m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]); |
---|
81 | m_PathEdit.SetValue(sPath); |
---|
82 | m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty); |
---|
83 | m_PathEdit.EnableWindow(!bPathEmpty); |
---|
84 | m_RegisterButton.EnableWindow(bPathEmpty || _tcsicmp(sPath, sLocalPath)); |
---|
85 | m_UnregisterButton.EnableWindow(!bPathEmpty); |
---|
86 | m_sPath = sPath; |
---|
87 | #pragma endregion |
---|
88 | #pragma region Per-User |
---|
89 | CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER); |
---|
90 | const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0; |
---|
91 | m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]); |
---|
92 | m_UserPathEdit.SetValue(sUserPath); |
---|
93 | m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty); |
---|
94 | m_UserPathEdit.EnableWindow(!bUserPathEmpty); |
---|
95 | m_UserRegisterButton.EnableWindow(bUserPathEmpty || _tcsicmp(sUserPath, sLocalPath)); |
---|
96 | m_UserUnregisterButton.EnableWindow(!bUserPathEmpty); |
---|
97 | m_sUserPath = sUserPath; |
---|
98 | #pragma endregion |
---|
99 | } |
---|
100 | |
---|
101 | // CDialogResize |
---|
102 | |
---|
103 | // Window message handlers |
---|
104 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
105 | { |
---|
106 | _ATLTRY |
---|
107 | { |
---|
108 | CWaitCursor WaitCursor; |
---|
109 | m_StatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_STATUS); |
---|
110 | m_PathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_PATH); |
---|
111 | m_RegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_REGISTER); |
---|
112 | m_UnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_UNREGISTER); |
---|
113 | m_UserStatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERSTATUS); |
---|
114 | m_UserPathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERPATH); |
---|
115 | m_UserRegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERREGISTER); |
---|
116 | m_UserUnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER); |
---|
117 | //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERNOTE))); |
---|
118 | //m_UserNoteStatic.SetIdealHeight(); |
---|
119 | if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008 |
---|
120 | { |
---|
121 | if(!IsAdministrator()) |
---|
122 | { |
---|
123 | m_RegisterButton.SetElevationRequiredState(TRUE); |
---|
124 | m_UnregisterButton.SetElevationRequiredState(TRUE); |
---|
125 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
126 | m_UserRegisterButton.SetElevationRequiredState(TRUE); |
---|
127 | m_UserUnregisterButton.SetElevationRequiredState(TRUE); |
---|
128 | } |
---|
129 | } |
---|
130 | _StringHelper::GetCommaSeparatedItems(AtlLoadString(IDC_REGISTRATION_REGISTRATION_STATUS), m_StatusArray); |
---|
131 | _A(m_StatusArray.GetCount() == 2); |
---|
132 | UpdateControls(); |
---|
133 | } |
---|
134 | _ATLCATCHALL() |
---|
135 | { |
---|
136 | for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT)) |
---|
137 | Window.EnableWindow(FALSE); |
---|
138 | _ATLRETHROW; |
---|
139 | } |
---|
140 | return TRUE; |
---|
141 | } |
---|
142 | LRESULT OnDestroy() |
---|
143 | { |
---|
144 | return 0; |
---|
145 | } |
---|
146 | INT OnSetActive() throw() |
---|
147 | { |
---|
148 | _ATLTRY |
---|
149 | { |
---|
150 | CWaitCursor WaitCursor; |
---|
151 | UpdateControls(); |
---|
152 | } |
---|
153 | _ATLCATCHALL() |
---|
154 | { |
---|
155 | _Z_EXCEPTION(); |
---|
156 | return -1; |
---|
157 | } |
---|
158 | return 0; |
---|
159 | } |
---|
160 | LRESULT OnRegister(UINT, INT, HWND) |
---|
161 | { |
---|
162 | _ATLTRY |
---|
163 | { |
---|
164 | CWaitCursor WaitCursor; |
---|
165 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
166 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE); |
---|
167 | if(bSilent) |
---|
168 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
169 | CancelToClose(); |
---|
170 | } |
---|
171 | _ATLCATCH(Exception) |
---|
172 | { |
---|
173 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
174 | } |
---|
175 | UpdateControls(); |
---|
176 | return 0; |
---|
177 | } |
---|
178 | LRESULT OnUnregister(UINT, INT, HWND) |
---|
179 | { |
---|
180 | _ATLTRY |
---|
181 | { |
---|
182 | CWaitCursor WaitCursor; |
---|
183 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
184 | const CPath& sPath = m_sPath; //GetPath(); |
---|
185 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
186 | if(bSilent) |
---|
187 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
188 | CancelToClose(); |
---|
189 | } |
---|
190 | _ATLCATCH(Exception) |
---|
191 | { |
---|
192 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
193 | } |
---|
194 | UpdateControls(); |
---|
195 | return 0; |
---|
196 | } |
---|
197 | LRESULT OnUserRegister(UINT, INT, HWND) |
---|
198 | { |
---|
199 | _ATLTRY |
---|
200 | { |
---|
201 | CWaitCursor WaitCursor; |
---|
202 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
203 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
204 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE); |
---|
205 | if(bSilent) |
---|
206 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
207 | CancelToClose(); |
---|
208 | } |
---|
209 | _ATLCATCH(Exception) |
---|
210 | { |
---|
211 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
212 | } |
---|
213 | UpdateControls(); |
---|
214 | return 0; |
---|
215 | } |
---|
216 | LRESULT OnUserUnregister(UINT, INT, HWND) |
---|
217 | { |
---|
218 | _ATLTRY |
---|
219 | { |
---|
220 | CWaitCursor WaitCursor; |
---|
221 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
222 | const CPath& sPath = m_sUserPath; //GetPath(); |
---|
223 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
224 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
225 | if(bSilent) |
---|
226 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
227 | CancelToClose(); |
---|
228 | } |
---|
229 | _ATLCATCH(Exception) |
---|
230 | { |
---|
231 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
232 | } |
---|
233 | UpdateControls(); |
---|
234 | return 0; |
---|
235 | } |
---|
236 | }; |
---|
237 | |
---|
238 | //////////////////////////////////////////////////////// |
---|
239 | // CProppageRegistrationPropertyPage |
---|
240 | |
---|
241 | class CProppageRegistrationPropertyPage : |
---|
242 | public CPropertyPageT<CProppageRegistrationPropertyPage>, |
---|
243 | //public CDialogResize<CProppageRegistrationPropertyPage>, |
---|
244 | public CWindowWithPrivateMessagesT<CProppageRegistrationPropertyPage> |
---|
245 | { |
---|
246 | public: |
---|
247 | enum { IDD = IDD_REGISTRATION_PROPPAGEREGISTRATION_PROPERTYPAGE }; |
---|
248 | |
---|
249 | BEGIN_MSG_MAP_EX(CProppageRegistrationPropertyPage) |
---|
250 | CHAIN_MSG_MAP(CPropertyPage) |
---|
251 | //CHAIN_MSG_MAP(CDialogResize<CProppageRegistrationPropertyPage>) |
---|
252 | CHAIN_MSG_MAP(CWindowWithPrivateMessages) |
---|
253 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
254 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_REGISTER, OnRegister) |
---|
255 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_UNREGISTER, OnUnregister) |
---|
256 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERREGISTER, OnUserRegister) |
---|
257 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERUNREGISTER, OnUserUnregister) |
---|
258 | REFLECT_NOTIFICATIONS() |
---|
259 | END_MSG_MAP() |
---|
260 | |
---|
261 | private: |
---|
262 | CRegistrationPropertySheet& m_PropertySheet; |
---|
263 | CRoEdit m_StatusEdit; |
---|
264 | CRoEdit m_PathEdit; |
---|
265 | CButton m_RegisterButton; |
---|
266 | CButton m_UnregisterButton; |
---|
267 | CRoEdit m_UserStatusEdit; |
---|
268 | CRoEdit m_UserPathEdit; |
---|
269 | CButton m_UserRegisterButton; |
---|
270 | CButton m_UserUnregisterButton; |
---|
271 | //CRoIconStatic m_UserNoteStatic; |
---|
272 | CRoArrayT<CString> m_StatusArray; |
---|
273 | CPath m_sPath; |
---|
274 | CPath m_sUserPath; |
---|
275 | |
---|
276 | public: |
---|
277 | // CProppageRegistrationPropertyPage |
---|
278 | CProppageRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
279 | m_PropertySheet(*pPropertySheet) |
---|
280 | { |
---|
281 | } |
---|
282 | VOID UpdateControls() |
---|
283 | { |
---|
284 | class __declspec(uuid("92A3A302-DA7C-4A1F-BA7E-1802BB5D2D02")) PSFactoryBuffer; |
---|
285 | _A(_pAtlModule); |
---|
286 | const CPath& sLocalPath = m_PropertySheet.m_sPropPagePath; |
---|
287 | #pragma region System |
---|
288 | //CPath sPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE); |
---|
289 | CPath sPath = FindClassPath(HKEY_LOCAL_MACHINE, __uuidof(PSFactoryBuffer)); |
---|
290 | const BOOL bPathEmpty = _tcslen(sPath) == 0; |
---|
291 | m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]); |
---|
292 | m_PathEdit.SetValue(sPath); |
---|
293 | m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty); |
---|
294 | m_PathEdit.EnableWindow(!bPathEmpty); |
---|
295 | m_RegisterButton.EnableWindow(bPathEmpty || _tcsicmp(sPath, sLocalPath)); |
---|
296 | m_UnregisterButton.EnableWindow(!bPathEmpty); |
---|
297 | m_sPath = sPath; |
---|
298 | #pragma endregion |
---|
299 | #pragma region Per-User |
---|
300 | //CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER); |
---|
301 | //const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0; |
---|
302 | //m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]); |
---|
303 | //m_UserPathEdit.SetValue(sUserPath); |
---|
304 | //m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty); |
---|
305 | //m_UserPathEdit.EnableWindow(!bUserPathEmpty); |
---|
306 | //m_UserRegisterButton.EnableWindow(bUserPathEmpty); |
---|
307 | //m_UserUnregisterButton.EnableWindow(!bUserPathEmpty); |
---|
308 | //m_sUserPath = sUserPath; |
---|
309 | #pragma endregion |
---|
310 | } |
---|
311 | |
---|
312 | // CDialogResize |
---|
313 | |
---|
314 | // Window message handlers |
---|
315 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
316 | { |
---|
317 | _ATLTRY |
---|
318 | { |
---|
319 | CWaitCursor WaitCursor; |
---|
320 | m_StatusEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_STATUS); |
---|
321 | m_PathEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_PATH); |
---|
322 | m_RegisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_REGISTER); |
---|
323 | m_UnregisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_UNREGISTER); |
---|
324 | m_UserStatusEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERSTATUS); |
---|
325 | m_UserPathEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERPATH); |
---|
326 | m_UserRegisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERREGISTER); |
---|
327 | m_UserUnregisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERUNREGISTER); |
---|
328 | //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERNOTE))); |
---|
329 | //m_UserNoteStatic.SetIdealHeight(); |
---|
330 | if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008 |
---|
331 | { |
---|
332 | if(!IsAdministrator()) |
---|
333 | { |
---|
334 | m_RegisterButton.SetElevationRequiredState(TRUE); |
---|
335 | m_UnregisterButton.SetElevationRequiredState(TRUE); |
---|
336 | } |
---|
337 | } |
---|
338 | _StringHelper::GetCommaSeparatedItems(AtlLoadString(IDC_REGISTRATION_PROPPAGEREGISTRATION_STATUS), m_StatusArray); |
---|
339 | _A(m_StatusArray.GetCount() == 2); |
---|
340 | UpdateControls(); |
---|
341 | } |
---|
342 | _ATLCATCHALL() |
---|
343 | { |
---|
344 | for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT)) |
---|
345 | Window.EnableWindow(FALSE); |
---|
346 | _ATLRETHROW; |
---|
347 | } |
---|
348 | return TRUE; |
---|
349 | } |
---|
350 | LRESULT OnDestroy() |
---|
351 | { |
---|
352 | return 0; |
---|
353 | } |
---|
354 | INT OnSetActive() throw() |
---|
355 | { |
---|
356 | _ATLTRY |
---|
357 | { |
---|
358 | CWaitCursor WaitCursor; |
---|
359 | UpdateControls(); |
---|
360 | } |
---|
361 | _ATLCATCHALL() |
---|
362 | { |
---|
363 | _Z_EXCEPTION(); |
---|
364 | return -1; |
---|
365 | } |
---|
366 | return 0; |
---|
367 | } |
---|
368 | LRESULT OnRegister(UINT, INT, HWND) |
---|
369 | { |
---|
370 | _ATLTRY |
---|
371 | { |
---|
372 | CWaitCursor WaitCursor; |
---|
373 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
374 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath), TRUE); |
---|
375 | if(bSilent) |
---|
376 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
377 | CancelToClose(); |
---|
378 | } |
---|
379 | _ATLCATCH(Exception) |
---|
380 | { |
---|
381 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
382 | } |
---|
383 | UpdateControls(); |
---|
384 | return 0; |
---|
385 | } |
---|
386 | LRESULT OnUnregister(UINT, INT, HWND) |
---|
387 | { |
---|
388 | _ATLTRY |
---|
389 | { |
---|
390 | CWaitCursor WaitCursor; |
---|
391 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
392 | const CPath& sPath = m_sPath; //m_PropertySheet.m_sPropPagePath |
---|
393 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
394 | if(bSilent) |
---|
395 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
396 | CancelToClose(); |
---|
397 | } |
---|
398 | _ATLCATCH(Exception) |
---|
399 | { |
---|
400 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
401 | } |
---|
402 | UpdateControls(); |
---|
403 | return 0; |
---|
404 | } |
---|
405 | LRESULT OnUserRegister(UINT, INT, HWND) |
---|
406 | { |
---|
407 | _ATLTRY |
---|
408 | { |
---|
409 | CWaitCursor WaitCursor; |
---|
410 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
411 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath)); |
---|
412 | if(bSilent) |
---|
413 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
414 | CancelToClose(); |
---|
415 | } |
---|
416 | _ATLCATCH(Exception) |
---|
417 | { |
---|
418 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
419 | } |
---|
420 | UpdateControls(); |
---|
421 | return 0; |
---|
422 | } |
---|
423 | LRESULT OnUserUnregister(UINT, INT, HWND) |
---|
424 | { |
---|
425 | _ATLTRY |
---|
426 | { |
---|
427 | CWaitCursor WaitCursor; |
---|
428 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
429 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath)); |
---|
430 | if(bSilent) |
---|
431 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
432 | CancelToClose(); |
---|
433 | } |
---|
434 | _ATLCATCH(Exception) |
---|
435 | { |
---|
436 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
437 | } |
---|
438 | UpdateControls(); |
---|
439 | return 0; |
---|
440 | } |
---|
441 | }; |
---|
442 | |
---|
443 | private: |
---|
444 | CRegistrationPropertyPage m_RegistrationPropertyPage; |
---|
445 | CProppageRegistrationPropertyPage m_ProppageRegistrationPropertyPage; |
---|
446 | CPath m_sPropPagePath; |
---|
447 | |
---|
448 | public: |
---|
449 | // CRegistrationPropertySheet |
---|
450 | CRegistrationPropertySheet() : |
---|
451 | CPropertySheetT<CRegistrationPropertySheet>(IDS_REGISTRATION_PROPERTYSHEETCAPTION), |
---|
452 | m_RegistrationPropertyPage(this), |
---|
453 | m_ProppageRegistrationPropertyPage(this) |
---|
454 | { |
---|
455 | AddPage(m_RegistrationPropertyPage); |
---|
456 | CPath sDirectory = GetPath(); |
---|
457 | sDirectory.RemoveFileSpec(); |
---|
458 | m_sPropPagePath.Combine(sDirectory, _T("proppage.dll")); |
---|
459 | if(m_sPropPagePath.FileExists()) |
---|
460 | AddPage(m_ProppageRegistrationPropertyPage); |
---|
461 | } |
---|
462 | BOOL SetInitialPosition() |
---|
463 | { |
---|
464 | if(!__super::SetInitialPosition()) |
---|
465 | return FALSE; |
---|
466 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
467 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
468 | #pragma region Indication of Bitness |
---|
469 | CString sCaption; |
---|
470 | _W(GetWindowText(sCaption)); |
---|
471 | #if defined(_WIN64) |
---|
472 | sCaption.Append(_T(" (64-bit)")); |
---|
473 | #else |
---|
474 | if(SafeIsWow64Process()) |
---|
475 | sCaption.Append(_T(" (32-bit)")); |
---|
476 | #endif // defined(_WIN64) |
---|
477 | _W(SetWindowText(sCaption)); |
---|
478 | #pragma endregion |
---|
479 | #pragma region System Menu |
---|
480 | CMenuHandle Menu = GetSystemMenu(FALSE); |
---|
481 | _W(Menu.AppendMenu(MF_SEPARATOR)); |
---|
482 | _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About..."))); |
---|
483 | #pragma endregion |
---|
484 | return TRUE; |
---|
485 | } |
---|
486 | static LPCTSTR GetTypeLibraryType() throw() |
---|
487 | { |
---|
488 | #if defined(_WIN64) |
---|
489 | static LPCTSTR g_pszTypeLibraryType = _T("win64"); |
---|
490 | #else |
---|
491 | static LPCTSTR g_pszTypeLibraryType = _T("win32"); |
---|
492 | #endif // defined(_WIN64) |
---|
493 | return g_pszTypeLibraryType; |
---|
494 | } |
---|
495 | static CPath FindTypeLibraryPath(const GUID& Identifier = _pAtlModule->m_libid) |
---|
496 | { |
---|
497 | CPath sPath; |
---|
498 | CRegKey Key; |
---|
499 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(HKEY_CLASSES_ROOT, AtlFormatString(_T("TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ)))) |
---|
500 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
501 | return sPath; |
---|
502 | } |
---|
503 | static CPath FindTypeLibraryPath(HKEY hRootKey, const GUID& Identifier = _pAtlModule->m_libid) |
---|
504 | { |
---|
505 | CPath sPath; |
---|
506 | CRegKey Key; |
---|
507 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ)))) |
---|
508 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
509 | return sPath; |
---|
510 | } |
---|
511 | static CPath FindClassPath(HKEY hRootKey, const GUID& Identifier) |
---|
512 | { |
---|
513 | CPath sPath; |
---|
514 | CRegKey Key; |
---|
515 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\CLSID\\%ls\\InProcServer32"), _PersistHelper::StringFromIdentifier(Identifier)), KEY_READ)))) |
---|
516 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
517 | return sPath; |
---|
518 | } |
---|
519 | static BOOL IsAdministrator() |
---|
520 | { |
---|
521 | bool bIsMember = FALSE; |
---|
522 | return CAccessToken().CheckTokenMembership(Sids::Admins(), &bIsMember) && bIsMember; |
---|
523 | } |
---|
524 | static HANDLE Execute(const CString& sParameters, BOOL bAsAdministrator = FALSE) |
---|
525 | { |
---|
526 | SHELLEXECUTEINFO Information; |
---|
527 | ZeroMemory(&Information, sizeof Information); |
---|
528 | Information.cbSize = sizeof Information; |
---|
529 | Information.fMask = SEE_MASK_NOCLOSEPROCESS; |
---|
530 | if(bAsAdministrator) |
---|
531 | Information.lpVerb = _T("runas"); |
---|
532 | Information.lpFile = _T("regsvr32.exe"); |
---|
533 | Information.nShow = SW_SHOWNORMAL; |
---|
534 | Information.lpParameters = sParameters; |
---|
535 | __E(ShellExecuteEx(&Information)); |
---|
536 | _Z4(atlTraceSync, 4, _T("Information.hInstApp 0x%p, .hProcess 0x%p\n"), Information.hInstApp, Information.hProcess); |
---|
537 | return Information.hProcess; |
---|
538 | } |
---|
539 | static DWORD ExecuteWait(const CString& sParameters, BOOL bAsAdministrator = FALSE) |
---|
540 | { |
---|
541 | CHandle Process; |
---|
542 | Process.Attach(Execute(sParameters, bAsAdministrator)); |
---|
543 | const DWORD nWaitResult = WaitForSingleObject(Process, INFINITE); |
---|
544 | _Z4(atlTraceSync, 4, _T("nWaitResult 0x%x\n"), nWaitResult); |
---|
545 | _A(nWaitResult == WAIT_OBJECT_0); |
---|
546 | DWORD nExitCode = 0; |
---|
547 | _W(GetExitCodeProcess(Process, &nExitCode)); |
---|
548 | _Z4(atlTraceGeneral, 4, _T("nExitCode %d (0x%x)\n"), nExitCode, nExitCode); |
---|
549 | return nExitCode; |
---|
550 | } |
---|
551 | static CPath GetPath() |
---|
552 | { |
---|
553 | TCHAR pszPath[MAX_PATH] = { 0 }; |
---|
554 | _W(GetModuleFileName(_AtlBaseModule.GetModuleInstance(), pszPath, DIM(pszPath))); |
---|
555 | return pszPath; |
---|
556 | } |
---|
557 | |
---|
558 | // Window message handelrs |
---|
559 | LRESULT OnSysCommand(UINT nCommand, CPoint) |
---|
560 | { |
---|
561 | switch(nCommand) |
---|
562 | { |
---|
563 | case ID_APP_ABOUT: |
---|
564 | { |
---|
565 | CAboutDialog Dialog; |
---|
566 | Dialog.DoModal(m_hWnd); |
---|
567 | } |
---|
568 | break; |
---|
569 | default: |
---|
570 | SetMsgHandled(FALSE); |
---|
571 | } |
---|
572 | return 0; |
---|
573 | } |
---|
574 | }; |
---|
575 | |
---|