Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.3 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include "..\Common\ServiceThread.h"
  4. #ifdef EXT_DEBUG
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. #include "advanced.h"
  9. #include "..\common\util.h"
  10. #include "resource.h"
  11. #include "EnvPage.h"
  12. #include "PerfPage.h"
  13. #include "StartupPage.h"
  14. #include "helpid.h"
  15. #include "common.h"
  16. // Help IDs
  17. DWORD aAdvancedHelpIds[] = {
  18. // IDC_ADV_PERF_TEXT, (IDH_ADVANCED + 0),
  19. IDC_ADV_PERF_TEXT, IDH_COMPUTER_MANAGEMENT_PERFORMANCE_GROUP_BOX,
  20. // IDC_ADV_PERF_BTN, (IDH_ADVANCED + 1),
  21. IDC_ADV_PERF_BTN, IDH_COMPUTER_MANAGEMENT_PERFORMANCE_SETTINGS_BUTTON,
  22. IDC_ADV_ENV_TEXT, (IDH_ADVANCED + 2),
  23. IDC_ADV_ENV_BTN, (IDH_ADVANCED + 3),
  24. IDC_ADV_RECOVERY_TEXT, (IDH_ADVANCED + 4),
  25. IDC_ADV_RECOVERY_BTN, (IDH_ADVANCED + 5),
  26. 0, 0
  27. };
  28. //------------------------------------------------------
  29. AdvancedPage::AdvancedPage(WbemServiceThread *serviceThread,
  30. LONG_PTR lNotifyHandle, bool bDeleteHandle, TCHAR* pTitle)
  31. : WBEMPageHelper(serviceThread),
  32. CSnapInPropertyPageImpl<AdvancedPage> (pTitle),
  33. m_lNotifyHandle(lNotifyHandle),
  34. m_bDeleteHandle(bDeleteHandle) // Should be true for only page.
  35. {
  36. }
  37. //------------------------------------------------------
  38. AdvancedPage::~AdvancedPage()
  39. {
  40. }
  41. //----------------------------------------------
  42. LRESULT AdvancedPage::OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  43. {
  44. m_hDlg = m_hWnd;
  45. if(m_serviceThread)
  46. {
  47. m_serviceThread->SendPtr(m_hWnd);
  48. }
  49. ::EnableWindow(GetDlgItem(IDC_ADV_PERF_BTN), FALSE);
  50. ::EnableWindow(GetDlgItem(IDC_ADV_ENV_BTN), FALSE);
  51. ::EnableWindow(GetDlgItem(IDC_ADV_RECOVERY_BTN), FALSE);
  52. return S_OK;
  53. }
  54. //----------------------------------------------
  55. LRESULT AdvancedPage::OnConnected(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  56. {
  57. if(lParam)
  58. {
  59. IStream *pStream = (IStream *)lParam;
  60. IWbemServices *pServices = 0;
  61. HRESULT hr = CoGetInterfaceAndReleaseStream(pStream,
  62. IID_IWbemServices,
  63. (void**)&pServices);
  64. if(SUCCEEDED(hr))
  65. {
  66. SetWbemService(pServices);
  67. pServices->Release();
  68. if(ServiceIsReady(NO_UI, 0, 0))
  69. {
  70. ::EnableWindow(GetDlgItem(IDC_ADV_PERF_BTN), TRUE);
  71. ::EnableWindow(GetDlgItem(IDC_ADV_ENV_BTN), TRUE);
  72. ::EnableWindow(GetDlgItem(IDC_ADV_RECOVERY_BTN), TRUE);
  73. }
  74. }
  75. }
  76. return S_OK;
  77. }
  78. //----------------------------------------------
  79. LRESULT AdvancedPage::OnF1Help(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  80. {
  81. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  82. L"sysdm.hlp",
  83. HELP_WM_HELP,
  84. (ULONG_PTR)(LPSTR)aAdvancedHelpIds);
  85. return S_OK;
  86. }
  87. //----------------------------------------------
  88. LRESULT AdvancedPage::OnContextHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  89. {
  90. ::WinHelp((HWND)wParam,
  91. L"sysdm.hlp",
  92. HELP_CONTEXTMENU,
  93. (ULONG_PTR)(LPSTR)aAdvancedHelpIds);
  94. return S_OK;
  95. }
  96. //----------------------------------------------
  97. LRESULT AdvancedPage::CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  98. {
  99. DWORD dwResult = 0;
  100. switch (wID)
  101. {
  102. case IDC_ADV_PERF_BTN:
  103. {
  104. g_fRebootRequired = FALSE;
  105. PerfPage perfPage(m_serviceThread);
  106. perfPage.DoModal(m_hDlg);
  107. }
  108. break;
  109. case IDC_ADV_ENV_BTN:
  110. {
  111. g_fRebootRequired = FALSE;
  112. EnvPage envPage(m_serviceThread);
  113. envPage.DoModal(m_hDlg);
  114. }
  115. break;
  116. case IDC_ADV_RECOVERY_BTN:
  117. {
  118. StartupPage startupPage(m_serviceThread);
  119. if(startupPage.DoModal(m_hDlg) == CLOSE_SNAPIN)
  120. {
  121. ::PostMessage(GetParent(), WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  122. }
  123. }
  124. break;
  125. default:
  126. return(FALSE);
  127. } // switch
  128. return(TRUE);
  129. }
  130. //----------------------------------------------
  131. BOOL AdvancedPage::OnApply()
  132. {
  133. // LPPSHNOTIFY psh;//TODO = (LPPSHNOTIFY)pnmh;
  134. // If the user is pressing "OK" and a reboot is required,
  135. // OLD WAY: send the PSM_REBOOTSYSTEM message.
  136. // NEW WAY: use WBEM.
  137. TCHAR msg[200] = {0};
  138. TCHAR caption[100] = {0};
  139. ::LoadString(HINST_THISDLL,
  140. IDS_SYS_CHANGE_CAPTION,
  141. caption, 100);
  142. ::LoadString(HINST_THISDLL,
  143. IDS_MUST_RESTART,
  144. msg, 200);
  145. if(/*(psh->lParam) && */
  146. g_fRebootRequired &&
  147. (::MessageBox(m_hDlg, msg, caption,
  148. MB_YESNO |
  149. MB_DEFBUTTON1 |
  150. MB_ICONQUESTION) == IDYES))
  151. {
  152. //OLD WAY: PropSheet_RebootSystem(GetParent(hDlg));
  153. // call the helper in the base class.
  154. HRESULT hr = Reboot();
  155. if(FAILED(hr))
  156. {
  157. TCHAR format[100] = {0};
  158. memset(msg, 0, 200 * sizeof(TCHAR));
  159. memset(caption, 0, 100 * sizeof(TCHAR));
  160. ::LoadString(HINST_THISDLL,
  161. IDS_ERR_EXECMETHOD_CAPTION,
  162. caption, 100);
  163. ::LoadString(HINST_THISDLL,
  164. IDS_ERR_EXECMETHOD,
  165. format, 100);
  166. CHString errorDescription;
  167. CHString errorMessage;
  168. ErrorLookup(hr, errorDescription);
  169. errorMessage.Format(format, errorDescription);
  170. ::MessageBox(m_hWnd, errorMessage, caption,
  171. MB_OK| MB_ICONEXCLAMATION);
  172. }
  173. } // if
  174. return TRUE;
  175. }