source: trunk/DirectShowSpy/Configuration.h @ 188

Last change on this file since 188 was 171, checked in by roman, 11 years ago

Fix for registration UI in XP

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