1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2014 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // This source code is published to complement DirectShowSpy developer powertoy |
---|
6 | // and demonstrate the internal use of APIs and tricks powering the tool. It is |
---|
7 | // allowed to freely re-use the portions of the code in other projects, commercial or otherwise |
---|
8 | // (provided that you dont pretend that you wrote the original tool). |
---|
9 | // |
---|
10 | // Please keep in mind that DirectShowSpy is a developer tool, it is strongly recommended |
---|
11 | // that it is not shipped with release grade software. The advise applies to hooking methods |
---|
12 | // used by DirectShowSpy in general as well. |
---|
13 | |
---|
14 | #pragma once |
---|
15 | |
---|
16 | #include <atlctrlx.h> |
---|
17 | #include <atlsplit.h> |
---|
18 | #include "rofiles.h" |
---|
19 | #include "AboutDialog.h" |
---|
20 | |
---|
21 | //////////////////////////////////////////////////////////// |
---|
22 | // CRegistrationPropertySheet |
---|
23 | |
---|
24 | class CRegistrationPropertySheet : |
---|
25 | public CPropertySheetT<CRegistrationPropertySheet> |
---|
26 | { |
---|
27 | public: |
---|
28 | |
---|
29 | BEGIN_MSG_MAP_EX(CRegistrationPropertySheet) |
---|
30 | CHAIN_MSG_MAP(CPropertySheet) |
---|
31 | MSG_WM_SYSCOMMAND(OnSysCommand) |
---|
32 | END_MSG_MAP() |
---|
33 | |
---|
34 | public: |
---|
35 | |
---|
36 | //////////////////////////////////////////////////////// |
---|
37 | // CRegistrationPropertyPage |
---|
38 | |
---|
39 | class CRegistrationPropertyPage : |
---|
40 | public CPropertyPageT<CRegistrationPropertyPage>, |
---|
41 | //public CDialogResize<CRegistrationPropertyPage>, |
---|
42 | public CWindowWithPrivateMessagesT<CRegistrationPropertyPage> |
---|
43 | { |
---|
44 | public: |
---|
45 | enum { IDD = IDD_REGISTRATION_REGISTRATION_PROPERTYPAGE }; |
---|
46 | |
---|
47 | BEGIN_MSG_MAP_EX(CRegistrationPropertyPage) |
---|
48 | CHAIN_MSG_MAP(CPropertyPage) |
---|
49 | //CHAIN_MSG_MAP(CDialogResize<CRegistrationPropertyPage>) |
---|
50 | CHAIN_MSG_MAP(CWindowWithPrivateMessages) |
---|
51 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
52 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_REGISTER, OnRegister) |
---|
53 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_UNREGISTER, OnUnregister) |
---|
54 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERREGISTER, OnUserRegister) |
---|
55 | COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER, OnUserUnregister) |
---|
56 | REFLECT_NOTIFICATIONS() |
---|
57 | END_MSG_MAP() |
---|
58 | |
---|
59 | private: |
---|
60 | CRegistrationPropertySheet& m_PropertySheet; |
---|
61 | CRoEdit m_StatusEdit; |
---|
62 | CRoEdit m_PathEdit; |
---|
63 | CButton m_RegisterButton; |
---|
64 | CButton m_UnregisterButton; |
---|
65 | CRoEdit m_UserStatusEdit; |
---|
66 | CRoEdit m_UserPathEdit; |
---|
67 | CButton m_UserRegisterButton; |
---|
68 | CButton m_UserUnregisterButton; |
---|
69 | //CRoIconStatic m_UserNoteStatic; |
---|
70 | CRoArrayT<CString> m_StatusArray; |
---|
71 | CPath m_sPath; |
---|
72 | CPath m_sUserPath; |
---|
73 | |
---|
74 | public: |
---|
75 | // CRegistrationPropertyPage |
---|
76 | CRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
77 | m_PropertySheet(*pPropertySheet) |
---|
78 | { |
---|
79 | } |
---|
80 | VOID UpdateControls() |
---|
81 | { |
---|
82 | _A(_pAtlModule); |
---|
83 | const CPath& sLocalPath = GetPath(); |
---|
84 | #pragma region System |
---|
85 | CPath sPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE); |
---|
86 | const BOOL bPathEmpty = _tcslen(sPath) == 0; |
---|
87 | m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]); |
---|
88 | m_PathEdit.SetValue(sPath); |
---|
89 | m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty); |
---|
90 | m_PathEdit.EnableWindow(!bPathEmpty); |
---|
91 | m_RegisterButton.EnableWindow(bPathEmpty || _tcsicmp(sPath, sLocalPath)); |
---|
92 | m_UnregisterButton.EnableWindow(!bPathEmpty); |
---|
93 | m_sPath = sPath; |
---|
94 | #pragma endregion |
---|
95 | #pragma region Per-User |
---|
96 | CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER); |
---|
97 | const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0; |
---|
98 | m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]); |
---|
99 | m_UserPathEdit.SetValue(sUserPath); |
---|
100 | m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty); |
---|
101 | m_UserPathEdit.EnableWindow(!bUserPathEmpty); |
---|
102 | m_UserRegisterButton.EnableWindow(bUserPathEmpty || _tcsicmp(sUserPath, sLocalPath)); |
---|
103 | m_UserUnregisterButton.EnableWindow(!bUserPathEmpty); |
---|
104 | m_sUserPath = sUserPath; |
---|
105 | #pragma endregion |
---|
106 | } |
---|
107 | |
---|
108 | // CDialogResize |
---|
109 | |
---|
110 | // Window message handlers |
---|
111 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
112 | { |
---|
113 | _ATLTRY |
---|
114 | { |
---|
115 | CWaitCursor WaitCursor; |
---|
116 | m_StatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_STATUS); |
---|
117 | m_PathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_PATH); |
---|
118 | m_RegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_REGISTER); |
---|
119 | m_UnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_UNREGISTER); |
---|
120 | m_UserStatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERSTATUS); |
---|
121 | m_UserPathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERPATH); |
---|
122 | m_UserRegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERREGISTER); |
---|
123 | m_UserUnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER); |
---|
124 | //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERNOTE))); |
---|
125 | //m_UserNoteStatic.SetIdealHeight(); |
---|
126 | if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008 |
---|
127 | { |
---|
128 | if(!IsAdministrator()) |
---|
129 | { |
---|
130 | m_RegisterButton.SetElevationRequiredState(TRUE); |
---|
131 | m_UnregisterButton.SetElevationRequiredState(TRUE); |
---|
132 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
133 | m_UserRegisterButton.SetElevationRequiredState(TRUE); |
---|
134 | m_UserUnregisterButton.SetElevationRequiredState(TRUE); |
---|
135 | } |
---|
136 | } |
---|
137 | _StringHelper::GetCommaSeparatedItems(AtlLoadString(IDC_REGISTRATION_REGISTRATION_STATUS), m_StatusArray); |
---|
138 | _A(m_StatusArray.GetCount() == 2); |
---|
139 | UpdateControls(); |
---|
140 | } |
---|
141 | _ATLCATCHALL() |
---|
142 | { |
---|
143 | for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT)) |
---|
144 | Window.EnableWindow(FALSE); |
---|
145 | _ATLRETHROW; |
---|
146 | } |
---|
147 | return TRUE; |
---|
148 | } |
---|
149 | LRESULT OnDestroy() |
---|
150 | { |
---|
151 | return 0; |
---|
152 | } |
---|
153 | INT OnSetActive() throw() |
---|
154 | { |
---|
155 | _ATLTRY |
---|
156 | { |
---|
157 | CWaitCursor WaitCursor; |
---|
158 | UpdateControls(); |
---|
159 | } |
---|
160 | _ATLCATCHALL() |
---|
161 | { |
---|
162 | _Z_EXCEPTION(); |
---|
163 | return -1; |
---|
164 | } |
---|
165 | return 0; |
---|
166 | } |
---|
167 | LRESULT OnRegister(UINT, INT, HWND) |
---|
168 | { |
---|
169 | _ATLTRY |
---|
170 | { |
---|
171 | CWaitCursor WaitCursor; |
---|
172 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
173 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE); |
---|
174 | if(bSilent) |
---|
175 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
176 | CancelToClose(); |
---|
177 | } |
---|
178 | _ATLCATCH(Exception) |
---|
179 | { |
---|
180 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
181 | } |
---|
182 | UpdateControls(); |
---|
183 | return 0; |
---|
184 | } |
---|
185 | LRESULT OnUnregister(UINT, INT, HWND) |
---|
186 | { |
---|
187 | _ATLTRY |
---|
188 | { |
---|
189 | CWaitCursor WaitCursor; |
---|
190 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
191 | const CPath& sPath = m_sPath; //GetPath(); |
---|
192 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
193 | if(bSilent) |
---|
194 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
195 | CancelToClose(); |
---|
196 | } |
---|
197 | _ATLCATCH(Exception) |
---|
198 | { |
---|
199 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
200 | } |
---|
201 | UpdateControls(); |
---|
202 | return 0; |
---|
203 | } |
---|
204 | LRESULT OnUserRegister(UINT, INT, HWND) |
---|
205 | { |
---|
206 | _ATLTRY |
---|
207 | { |
---|
208 | CWaitCursor WaitCursor; |
---|
209 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
210 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
211 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE); |
---|
212 | if(bSilent) |
---|
213 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
214 | CancelToClose(); |
---|
215 | } |
---|
216 | _ATLCATCH(Exception) |
---|
217 | { |
---|
218 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
219 | } |
---|
220 | UpdateControls(); |
---|
221 | return 0; |
---|
222 | } |
---|
223 | LRESULT OnUserUnregister(UINT, INT, HWND) |
---|
224 | { |
---|
225 | _ATLTRY |
---|
226 | { |
---|
227 | CWaitCursor WaitCursor; |
---|
228 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
229 | const CPath& sPath = m_sUserPath; //GetPath(); |
---|
230 | // NOTE: Even per-user registration needs elevation, since we are hooking COM classes |
---|
231 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
232 | if(bSilent) |
---|
233 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
234 | CancelToClose(); |
---|
235 | } |
---|
236 | _ATLCATCH(Exception) |
---|
237 | { |
---|
238 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
239 | } |
---|
240 | UpdateControls(); |
---|
241 | return 0; |
---|
242 | } |
---|
243 | }; |
---|
244 | |
---|
245 | //////////////////////////////////////////////////////// |
---|
246 | // CModuleRegisrtationPropertyPageT |
---|
247 | |
---|
248 | template <typename T> |
---|
249 | class CModuleRegisrtationPropertyPageT : |
---|
250 | public CPropertyPageT<T>, |
---|
251 | //public CDialogResize<T>, |
---|
252 | public CWindowWithPrivateMessagesT<T> |
---|
253 | { |
---|
254 | protected: |
---|
255 | typedef CModuleRegisrtationPropertyPageT<T> CModuleRegisrtationPropertyPage; |
---|
256 | |
---|
257 | public: |
---|
258 | |
---|
259 | BEGIN_MSG_MAP_EX(CProppageRegistrationPropertyPagCModuleRegisrtationPropertyPage) |
---|
260 | CHAIN_MSG_MAP(CPropertyPage) |
---|
261 | //CHAIN_MSG_MAP(CDialogResize<T>) |
---|
262 | CHAIN_MSG_MAP(CWindowWithPrivateMessages) |
---|
263 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
264 | COMMAND_ID_HANDLER_EX(T::IDD + IDC_REGISTER, OnRegister) |
---|
265 | COMMAND_ID_HANDLER_EX(T::IDD + IDC_UNREGISTER, OnUnregister) |
---|
266 | COMMAND_ID_HANDLER_EX(T::IDD + IDC_USERREGISTER, OnUserRegister) |
---|
267 | COMMAND_ID_HANDLER_EX(T::IDD + IDC_USERUNREGISTER, OnUserUnregister) |
---|
268 | REFLECT_NOTIFICATIONS() |
---|
269 | END_MSG_MAP() |
---|
270 | |
---|
271 | public: |
---|
272 | |
---|
273 | //////////////////////////////////////////////////// |
---|
274 | // Resource Identifiers |
---|
275 | |
---|
276 | enum |
---|
277 | { |
---|
278 | //IDD_PROPERTYPAGE, |
---|
279 | IDC_STATUS = 10, |
---|
280 | IDC_PATH = 11, |
---|
281 | IDC_REGISTER = 12, |
---|
282 | IDC_UNREGISTER = 13, |
---|
283 | IDC_USERSTATUS = 14, |
---|
284 | IDC_USERPATH = 21, |
---|
285 | IDC_USERREGISTER = 22, |
---|
286 | IDC_USERUNREGISTER = 23, |
---|
287 | IDC_USERNOTE = 24, |
---|
288 | }; |
---|
289 | |
---|
290 | private: |
---|
291 | CPath m_sLocalPath; |
---|
292 | CRegistrationPropertySheet& m_PropertySheet; |
---|
293 | CRoEdit m_StatusEdit; |
---|
294 | CRoEdit m_PathEdit; |
---|
295 | CButton m_RegisterButton; |
---|
296 | CButton m_UnregisterButton; |
---|
297 | CRoEdit m_UserStatusEdit; |
---|
298 | CRoEdit m_UserPathEdit; |
---|
299 | CButton m_UserRegisterButton; |
---|
300 | CButton m_UserUnregisterButton; |
---|
301 | //CRoIconStatic m_UserNoteStatic; |
---|
302 | CRoArrayT<CString> m_StatusArray; |
---|
303 | CPath m_sPath; |
---|
304 | CPath m_sUserPath; |
---|
305 | |
---|
306 | public: |
---|
307 | // CModuleRegisrtationPropertyPageT |
---|
308 | CModuleRegisrtationPropertyPageT(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
309 | m_PropertySheet(*pPropertySheet) |
---|
310 | { |
---|
311 | } |
---|
312 | VOID SetLocalPath(const CPath& sLocalPath) |
---|
313 | { |
---|
314 | _A(!_tcslen(m_sLocalPath) && _tcslen(sLocalPath)); |
---|
315 | m_sLocalPath = sLocalPath; |
---|
316 | } |
---|
317 | VOID UpdateControls() |
---|
318 | { |
---|
319 | _A(_pAtlModule); |
---|
320 | const CPath& sLocalPath = m_sLocalPath; |
---|
321 | _A(_tcslen(m_sLocalPath)); |
---|
322 | _A(m_sLocalPath.FileExists()); |
---|
323 | #pragma region System |
---|
324 | //CPath sPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE); |
---|
325 | CPath sPath = FindClassPath(HKEY_LOCAL_MACHINE, T::GetSampleClassIdentifier()); |
---|
326 | const BOOL bPathEmpty = _tcslen(sPath) == 0; |
---|
327 | m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]); |
---|
328 | m_PathEdit.SetValue(sPath); |
---|
329 | m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty); |
---|
330 | m_PathEdit.EnableWindow(!bPathEmpty); |
---|
331 | m_RegisterButton.EnableWindow(bPathEmpty || _tcsicmp(sPath, sLocalPath)); |
---|
332 | m_UnregisterButton.EnableWindow(!bPathEmpty); |
---|
333 | m_sPath = sPath; |
---|
334 | #pragma endregion |
---|
335 | #pragma region Per-User |
---|
336 | //CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER); |
---|
337 | //const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0; |
---|
338 | //m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]); |
---|
339 | //m_UserPathEdit.SetValue(sUserPath); |
---|
340 | //m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty); |
---|
341 | //m_UserPathEdit.EnableWindow(!bUserPathEmpty); |
---|
342 | //m_UserRegisterButton.EnableWindow(bUserPathEmpty); |
---|
343 | //m_UserUnregisterButton.EnableWindow(!bUserPathEmpty); |
---|
344 | //m_sUserPath = sUserPath; |
---|
345 | #pragma endregion |
---|
346 | } |
---|
347 | |
---|
348 | // CDialogResize |
---|
349 | |
---|
350 | // Window message handlers |
---|
351 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
352 | { |
---|
353 | _ATLTRY |
---|
354 | { |
---|
355 | CWaitCursor WaitCursor; |
---|
356 | m_StatusEdit = GetDlgItem(T::IDD + IDC_STATUS); |
---|
357 | m_PathEdit = GetDlgItem(T::IDD + IDC_PATH); |
---|
358 | m_RegisterButton = GetDlgItem(T::IDD + IDC_REGISTER); |
---|
359 | m_UnregisterButton = GetDlgItem(T::IDD + IDC_UNREGISTER); |
---|
360 | m_UserStatusEdit = GetDlgItem(T::IDD + IDC_USERSTATUS); |
---|
361 | m_UserPathEdit = GetDlgItem(T::IDD + IDC_USERPATH); |
---|
362 | m_UserRegisterButton = GetDlgItem(T::IDD + IDC_USERREGISTER); |
---|
363 | m_UserUnregisterButton = GetDlgItem(T::IDD + IDC_USERUNREGISTER); |
---|
364 | //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(T::IDD + IDC_USERNOTE))); |
---|
365 | //m_UserNoteStatic.SetIdealHeight(); |
---|
366 | if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008 |
---|
367 | { |
---|
368 | if(!IsAdministrator()) |
---|
369 | { |
---|
370 | m_RegisterButton.SetElevationRequiredState(TRUE); |
---|
371 | m_UnregisterButton.SetElevationRequiredState(TRUE); |
---|
372 | } |
---|
373 | } |
---|
374 | _StringHelper::GetCommaSeparatedItems(AtlLoadString(T::IDD + IDC_STATUS), m_StatusArray); |
---|
375 | _A(m_StatusArray.GetCount() == 2); |
---|
376 | UpdateControls(); |
---|
377 | } |
---|
378 | _ATLCATCHALL() |
---|
379 | { |
---|
380 | for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT)) |
---|
381 | Window.EnableWindow(FALSE); |
---|
382 | _ATLRETHROW; |
---|
383 | } |
---|
384 | return TRUE; |
---|
385 | } |
---|
386 | LRESULT OnDestroy() |
---|
387 | { |
---|
388 | return 0; |
---|
389 | } |
---|
390 | INT OnSetActive() throw() |
---|
391 | { |
---|
392 | _ATLTRY |
---|
393 | { |
---|
394 | CWaitCursor WaitCursor; |
---|
395 | UpdateControls(); |
---|
396 | } |
---|
397 | _ATLCATCHALL() |
---|
398 | { |
---|
399 | _Z_EXCEPTION(); |
---|
400 | return -1; |
---|
401 | } |
---|
402 | return 0; |
---|
403 | } |
---|
404 | LRESULT OnRegister(UINT, INT, HWND) |
---|
405 | { |
---|
406 | _ATLTRY |
---|
407 | { |
---|
408 | CWaitCursor WaitCursor; |
---|
409 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
410 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), m_sLocalPath), TRUE); |
---|
411 | if(bSilent) |
---|
412 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
413 | CancelToClose(); |
---|
414 | } |
---|
415 | _ATLCATCH(Exception) |
---|
416 | { |
---|
417 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
418 | } |
---|
419 | UpdateControls(); |
---|
420 | return 0; |
---|
421 | } |
---|
422 | LRESULT OnUnregister(UINT, INT, HWND) |
---|
423 | { |
---|
424 | _ATLTRY |
---|
425 | { |
---|
426 | CWaitCursor WaitCursor; |
---|
427 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
428 | const CPath& sPath = m_sPath; //m_sLocalPath |
---|
429 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE); |
---|
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 | LRESULT OnUserRegister(UINT, INT, HWND) |
---|
442 | { |
---|
443 | _ATLTRY |
---|
444 | { |
---|
445 | CWaitCursor WaitCursor; |
---|
446 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
447 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), m_sLocalPath)); |
---|
448 | if(bSilent) |
---|
449 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
450 | CancelToClose(); |
---|
451 | } |
---|
452 | _ATLCATCH(Exception) |
---|
453 | { |
---|
454 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
455 | } |
---|
456 | UpdateControls(); |
---|
457 | return 0; |
---|
458 | } |
---|
459 | LRESULT OnUserUnregister(UINT, INT, HWND) |
---|
460 | { |
---|
461 | _ATLTRY |
---|
462 | { |
---|
463 | CWaitCursor WaitCursor; |
---|
464 | const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1); |
---|
465 | const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), m_sLocalPath)); |
---|
466 | if(bSilent) |
---|
467 | MessageBeep(nExitCode ? MB_ICONERROR : MB_OK); |
---|
468 | CancelToClose(); |
---|
469 | } |
---|
470 | _ATLCATCH(Exception) |
---|
471 | { |
---|
472 | AtlExceptionMessageBox(m_hWnd, Exception); |
---|
473 | } |
---|
474 | UpdateControls(); |
---|
475 | return 0; |
---|
476 | } |
---|
477 | }; |
---|
478 | |
---|
479 | //////////////////////////////////////////////////////// |
---|
480 | // CProppageRegistrationPropertyPage |
---|
481 | |
---|
482 | class CProppageRegistrationPropertyPage : |
---|
483 | public CModuleRegisrtationPropertyPageT<CProppageRegistrationPropertyPage> |
---|
484 | { |
---|
485 | public: |
---|
486 | enum { IDD = IDD_REGISTRATION_PROPPAGEREGISTRATION_PROPERTYPAGE }; |
---|
487 | |
---|
488 | BEGIN_MSG_MAP_EX(CProppageRegistrationPropertyPage) |
---|
489 | CHAIN_MSG_MAP(CModuleRegisrtationPropertyPage) |
---|
490 | END_MSG_MAP() |
---|
491 | |
---|
492 | public: |
---|
493 | // CProppageRegistrationPropertyPage |
---|
494 | CProppageRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
495 | CModuleRegisrtationPropertyPageT<CProppageRegistrationPropertyPage>(pPropertySheet) |
---|
496 | { |
---|
497 | } |
---|
498 | static CLSID GetSampleClassIdentifier() throw() |
---|
499 | { |
---|
500 | class __declspec(uuid("92A3A302-DA7C-4A1F-BA7E-1802BB5D2D02")) PSFactoryBuffer; |
---|
501 | return __uuidof(PSFactoryBuffer); |
---|
502 | } |
---|
503 | |
---|
504 | // Window message handlers |
---|
505 | }; |
---|
506 | |
---|
507 | //////////////////////////////////////////////////////// |
---|
508 | // CEvrpropRegistrationPropertyPage |
---|
509 | |
---|
510 | class CEvrpropRegistrationPropertyPage : |
---|
511 | public CModuleRegisrtationPropertyPageT<CEvrpropRegistrationPropertyPage> |
---|
512 | { |
---|
513 | public: |
---|
514 | enum { IDD = IDD_REGISTRATION_EVRPROPREGISTRATION_PROPERTYPAGE }; |
---|
515 | |
---|
516 | BEGIN_MSG_MAP_EX(CEvrpropRegistrationPropertyPage) |
---|
517 | CHAIN_MSG_MAP(CModuleRegisrtationPropertyPage) |
---|
518 | END_MSG_MAP() |
---|
519 | |
---|
520 | public: |
---|
521 | // CEvrpropRegistrationPropertyPage |
---|
522 | CEvrpropRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() : |
---|
523 | CModuleRegisrtationPropertyPageT<CEvrpropRegistrationPropertyPage>(pPropertySheet) |
---|
524 | { |
---|
525 | } |
---|
526 | static CLSID GetSampleClassIdentifier() throw() |
---|
527 | { |
---|
528 | class __declspec(uuid("7C737B87-2760-4183-B5B4-ACA7C64DD720")) EvrMixerControl; |
---|
529 | return __uuidof(EvrMixerControl); |
---|
530 | } |
---|
531 | |
---|
532 | // Window message handlers |
---|
533 | }; |
---|
534 | |
---|
535 | private: |
---|
536 | CRegistrationPropertyPage m_RegistrationPropertyPage; |
---|
537 | CProppageRegistrationPropertyPage m_ProppageRegistrationPropertyPage; |
---|
538 | CEvrpropRegistrationPropertyPage m_EvrpropRegistrationPropertyPage; |
---|
539 | CPath m_sProppagePath; |
---|
540 | CPath m_sEvrpropPath; |
---|
541 | |
---|
542 | public: |
---|
543 | // CRegistrationPropertySheet |
---|
544 | CRegistrationPropertySheet() : |
---|
545 | CPropertySheetT<CRegistrationPropertySheet>(IDS_REGISTRATION_PROPERTYSHEETCAPTION), |
---|
546 | m_RegistrationPropertyPage(this), |
---|
547 | m_ProppageRegistrationPropertyPage(this), |
---|
548 | m_EvrpropRegistrationPropertyPage(this) |
---|
549 | { |
---|
550 | AddPage(m_RegistrationPropertyPage); |
---|
551 | CPath sDirectory = GetPath(); |
---|
552 | sDirectory.RemoveFileSpec(); |
---|
553 | m_sProppagePath.Combine(sDirectory, _T("proppage.dll")); |
---|
554 | if(m_sProppagePath.FileExists()) |
---|
555 | { |
---|
556 | m_ProppageRegistrationPropertyPage.SetLocalPath(m_sProppagePath); |
---|
557 | AddPage(m_ProppageRegistrationPropertyPage); |
---|
558 | } |
---|
559 | m_sEvrpropPath.Combine(sDirectory, _T("evrprop.dll")); |
---|
560 | if(m_sEvrpropPath.FileExists()) |
---|
561 | { |
---|
562 | m_EvrpropRegistrationPropertyPage.SetLocalPath(m_sEvrpropPath); |
---|
563 | AddPage(m_EvrpropRegistrationPropertyPage); |
---|
564 | } |
---|
565 | } |
---|
566 | BOOL SetInitialPosition() |
---|
567 | { |
---|
568 | if(!__super::SetInitialPosition()) |
---|
569 | return FALSE; |
---|
570 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
571 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
572 | #pragma region Indication of Bitness |
---|
573 | CString sCaption; |
---|
574 | _W(GetWindowText(sCaption)); |
---|
575 | #if defined(_WIN64) |
---|
576 | sCaption.Append(_T(" (64-bit)")); |
---|
577 | #else |
---|
578 | if(SafeIsWow64Process()) |
---|
579 | sCaption.Append(_T(" (32-bit)")); |
---|
580 | #endif // defined(_WIN64) |
---|
581 | _W(SetWindowText(sCaption)); |
---|
582 | #pragma endregion |
---|
583 | #pragma region System Menu |
---|
584 | CMenuHandle Menu = GetSystemMenu(FALSE); |
---|
585 | _W(Menu.AppendMenu(MF_SEPARATOR)); |
---|
586 | _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About..."))); |
---|
587 | #pragma endregion |
---|
588 | return TRUE; |
---|
589 | } |
---|
590 | static LPCTSTR GetTypeLibraryType() throw() |
---|
591 | { |
---|
592 | #if defined(_WIN64) |
---|
593 | static LPCTSTR g_pszTypeLibraryType = _T("win64"); |
---|
594 | #else |
---|
595 | static LPCTSTR g_pszTypeLibraryType = _T("win32"); |
---|
596 | #endif // defined(_WIN64) |
---|
597 | return g_pszTypeLibraryType; |
---|
598 | } |
---|
599 | static CPath FindTypeLibraryPath(const GUID& Identifier = _pAtlModule->m_libid) |
---|
600 | { |
---|
601 | CPath sPath; |
---|
602 | CRegKey Key; |
---|
603 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(HKEY_CLASSES_ROOT, AtlFormatString(_T("TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ)))) |
---|
604 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
605 | return sPath; |
---|
606 | } |
---|
607 | static CPath FindTypeLibraryPath(HKEY hRootKey, const GUID& Identifier = _pAtlModule->m_libid) |
---|
608 | { |
---|
609 | CPath sPath; |
---|
610 | CRegKey Key; |
---|
611 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ)))) |
---|
612 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
613 | return sPath; |
---|
614 | } |
---|
615 | static CPath FindClassPath(HKEY hRootKey, const GUID& Identifier) |
---|
616 | { |
---|
617 | CPath sPath; |
---|
618 | CRegKey Key; |
---|
619 | if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\CLSID\\%ls\\InProcServer32"), _PersistHelper::StringFromIdentifier(Identifier)), KEY_READ)))) |
---|
620 | sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key); |
---|
621 | return sPath; |
---|
622 | } |
---|
623 | static BOOL IsAdministrator() |
---|
624 | { |
---|
625 | bool bIsMember = FALSE; |
---|
626 | return CAccessToken().CheckTokenMembership(Sids::Admins(), &bIsMember) && bIsMember; |
---|
627 | } |
---|
628 | static HANDLE Execute(const CString& sParameters, BOOL bAsAdministrator = FALSE) |
---|
629 | { |
---|
630 | SHELLEXECUTEINFO Information; |
---|
631 | ZeroMemory(&Information, sizeof Information); |
---|
632 | Information.cbSize = sizeof Information; |
---|
633 | Information.fMask = SEE_MASK_NOCLOSEPROCESS; |
---|
634 | if(bAsAdministrator && GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008 |
---|
635 | Information.lpVerb = _T("runas"); |
---|
636 | Information.lpFile = _T("regsvr32.exe"); |
---|
637 | Information.nShow = SW_SHOWNORMAL; |
---|
638 | Information.lpParameters = sParameters; |
---|
639 | __E(ShellExecuteEx(&Information)); |
---|
640 | _Z4(atlTraceSync, 4, _T("Information.hInstApp 0x%p, .hProcess 0x%p\n"), Information.hInstApp, Information.hProcess); |
---|
641 | return Information.hProcess; |
---|
642 | } |
---|
643 | static DWORD ExecuteWait(const CString& sParameters, BOOL bAsAdministrator = FALSE) |
---|
644 | { |
---|
645 | CHandle Process; |
---|
646 | Process.Attach(Execute(sParameters, bAsAdministrator)); |
---|
647 | const DWORD nWaitResult = WaitForSingleObject(Process, INFINITE); |
---|
648 | _Z4(atlTraceSync, 4, _T("nWaitResult 0x%x\n"), nWaitResult); |
---|
649 | _A(nWaitResult == WAIT_OBJECT_0); |
---|
650 | DWORD nExitCode = 0; |
---|
651 | _W(GetExitCodeProcess(Process, &nExitCode)); |
---|
652 | _Z4(atlTraceGeneral, 4, _T("nExitCode %d (0x%x)\n"), nExitCode, nExitCode); |
---|
653 | return nExitCode; |
---|
654 | } |
---|
655 | static CPath GetPath() |
---|
656 | { |
---|
657 | TCHAR pszPath[MAX_PATH] = { 0 }; |
---|
658 | _W(GetModuleFileName(_AtlBaseModule.GetModuleInstance(), pszPath, DIM(pszPath))); |
---|
659 | return pszPath; |
---|
660 | } |
---|
661 | |
---|
662 | // Window message handelrs |
---|
663 | LRESULT OnSysCommand(UINT nCommand, CPoint) |
---|
664 | { |
---|
665 | switch(nCommand) |
---|
666 | { |
---|
667 | case ID_APP_ABOUT: |
---|
668 | { |
---|
669 | CAboutDialog Dialog; |
---|
670 | Dialog.DoModal(m_hWnd); |
---|
671 | } |
---|
672 | break; |
---|
673 | default: |
---|
674 | SetMsgHandled(FALSE); |
---|
675 | } |
---|
676 | return 0; |
---|
677 | } |
---|
678 | }; |
---|
679 | |
---|