source: trunk/DirectShowSpy/Configuration.h @ 543

Last change on this file since 543 was 432, checked in by roman, 9 years ago

VS2013 related updates; use of CSIDL_LOCAL_APPDATA instead of CSIDL_APPDATA for fallback log writes; added bitness and privilege indication in all captions

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