source: trunk/DirectShowSpy/Configuration.h @ 223

Last change on this file since 223 was 196, checked in by roman, 11 years ago

Cosmetic fixes, new .BAT names, UnregisterTreatAsClasses? export to force removal of TreatAs? keys

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