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