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.

388 lines
12 KiB

  1. #include "stdafx.h"
  2. #include "PageGeneral.h"
  3. #include "PageServices.h"
  4. #include "PageStartup.h"
  5. #include "PageBootIni.h"
  6. #include "PageIni.h"
  7. #include "PageGeneral.h"
  8. #include "ExpandDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. #define WM_SETCANCELTOCLOSE WM_USER + 1
  15. extern CPageServices * ppageServices;
  16. extern CPageStartup * ppageStartup;
  17. extern CPageBootIni * ppageBootIni;
  18. extern CPageIni * ppageWinIni;
  19. extern CPageIni * ppageSystemIni;
  20. extern CPageGeneral * ppageGeneral;
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CPageGeneral property page
  23. IMPLEMENT_DYNCREATE(CPageGeneral, CPropertyPage)
  24. CPageGeneral::CPageGeneral() : CPropertyPage(CPageGeneral::IDD)
  25. {
  26. //{{AFX_DATA_INIT(CPageGeneral)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. m_fForceSelectiveRadio = FALSE;
  30. }
  31. CPageGeneral::~CPageGeneral()
  32. {
  33. }
  34. void CPageGeneral::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CPageGeneral)
  38. // NOTE: the ClassWizard will add DDX and DDV calls here
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CPageGeneral, CPropertyPage)
  42. //{{AFX_MSG_MAP(CPageGeneral)
  43. ON_BN_CLICKED(IDC_DIAGNOSTICSTARTUP, OnDiagnosticStartup)
  44. ON_BN_CLICKED(IDC_NORMALSTARTUP, OnNormalStartup)
  45. ON_BN_CLICKED(IDC_SELECTIVESTARTUP, OnSelectiveStartup)
  46. ON_BN_CLICKED(IDC_CHECK_PROCSYSINI, OnCheckProcSysIni)
  47. ON_BN_CLICKED(IDC_CHECKLOADSTARTUPITEMS, OnCheckStartupItems)
  48. ON_BN_CLICKED(IDC_CHECKLOADSYSSERVICES, OnCheckServices)
  49. ON_BN_CLICKED(IDC_CHECKPROCWININI, OnCheckWinIni)
  50. ON_MESSAGE(WM_SETCANCELTOCLOSE, OnSetCancelToClose)
  51. ON_BN_CLICKED(IDC_RADIOMODIFIED, OnRadioModified)
  52. ON_BN_CLICKED(IDC_RADIOORIGINAL, OnRadioOriginal)
  53. ON_BN_CLICKED(IDC_BUTTONEXTRACT, OnButtonExtract)
  54. ON_BN_CLICKED(IDC_BUTTONLAUNCHSYSRESTORE, OnButtonSystemRestore)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CPageGeneral message handlers
  59. BOOL CPageGeneral::OnInitDialog()
  60. {
  61. CPropertyPage::OnInitDialog();
  62. // Check to see if system restore is on this system (it should be).
  63. BOOL fSysRestorePresent = FALSE;
  64. TCHAR szPath[MAX_PATH];
  65. if (::ExpandEnvironmentStrings(_T("%windir%\\system32\\restore\\rstrui.exe"), szPath, MAX_PATH))
  66. fSysRestorePresent = FileExists(szPath);
  67. ::EnableWindow(GetDlgItemHWND(IDC_BUTTONLAUNCHSYSRESTORE), fSysRestorePresent);
  68. // Hide the radio buttons for BOOT.INI if there isn't any such page.
  69. if (NULL == ppageBootIni)
  70. {
  71. ::ShowWindow(GetDlgItemHWND(IDC_RADIOORIGINAL), SW_HIDE);
  72. ::ShowWindow(GetDlgItemHWND(IDC_RADIOMODIFIED), SW_HIDE);
  73. }
  74. return TRUE; // return TRUE unless you set the focus to a control
  75. }
  76. //-------------------------------------------------------------------------
  77. // When the this tab is shown, we should update the buttons based on the
  78. // states of the other tabs.
  79. //-------------------------------------------------------------------------
  80. BOOL CPageGeneral::OnSetActive()
  81. {
  82. UpdateControls();
  83. return TRUE;
  84. }
  85. //-------------------------------------------------------------------------
  86. // Update the controls on the general tab based on the state of all the
  87. // other tabs.
  88. //-------------------------------------------------------------------------
  89. void CPageGeneral::UpdateControls()
  90. {
  91. // Get the state for each tabs. The state will be set in the check box
  92. // associated with the particular tab, and an overall state will be
  93. // maintained.
  94. BOOL fAllNormal = TRUE;
  95. BOOL fAllDiagnostic = TRUE;
  96. if (ppageSystemIni)
  97. UpdateCheckBox(ppageSystemIni, IDC_CHECK_PROCSYSINI, fAllNormal, fAllDiagnostic);
  98. if (ppageWinIni)
  99. UpdateCheckBox(ppageWinIni, IDC_CHECKPROCWININI, fAllNormal, fAllDiagnostic);
  100. if (ppageServices)
  101. UpdateCheckBox(ppageServices, IDC_CHECKLOADSYSSERVICES, fAllNormal, fAllDiagnostic);
  102. if (ppageStartup)
  103. UpdateCheckBox(ppageStartup, IDC_CHECKLOADSTARTUPITEMS, fAllNormal, fAllDiagnostic);
  104. if (ppageBootIni)
  105. {
  106. if (NORMAL == dynamic_cast<CPageBase *>(ppageBootIni)->GetCurrentTabState())
  107. CheckRadioButton(IDC_RADIOORIGINAL, IDC_RADIOMODIFIED, IDC_RADIOORIGINAL);
  108. else
  109. {
  110. fAllNormal = FALSE;
  111. CheckRadioButton(IDC_RADIOORIGINAL, IDC_RADIOMODIFIED, IDC_RADIOMODIFIED);
  112. }
  113. }
  114. // Set the radio button based on the states of the tabs.
  115. if (fAllNormal && !m_fForceSelectiveRadio)
  116. CheckRadioButton(IDC_NORMALSTARTUP, IDC_SELECTIVESTARTUP, IDC_NORMALSTARTUP);
  117. else if (fAllDiagnostic && !m_fForceSelectiveRadio)
  118. CheckRadioButton(IDC_NORMALSTARTUP, IDC_SELECTIVESTARTUP, IDC_DIAGNOSTICSTARTUP);
  119. else
  120. CheckRadioButton(IDC_NORMALSTARTUP, IDC_SELECTIVESTARTUP, IDC_SELECTIVESTARTUP);
  121. ::EnableWindow(GetDlgItemHWND(IDC_CHECK_PROCSYSINI), ((!fAllNormal && !fAllDiagnostic) || m_fForceSelectiveRadio));
  122. ::EnableWindow(GetDlgItemHWND(IDC_CHECKPROCWININI), ((!fAllNormal && !fAllDiagnostic) || m_fForceSelectiveRadio));
  123. ::EnableWindow(GetDlgItemHWND(IDC_CHECKLOADSYSSERVICES), ((!fAllNormal && !fAllDiagnostic) || m_fForceSelectiveRadio));
  124. ::EnableWindow(GetDlgItemHWND(IDC_CHECKLOADSTARTUPITEMS), ((!fAllNormal && !fAllDiagnostic) || m_fForceSelectiveRadio));
  125. if (ppageBootIni)
  126. {
  127. if ((!fAllNormal && !fAllDiagnostic) || m_fForceSelectiveRadio)
  128. {
  129. ::EnableWindow(GetDlgItemHWND(IDC_RADIOORIGINAL), TRUE);
  130. ::EnableWindow(GetDlgItemHWND(IDC_RADIOMODIFIED), (IDC_RADIOMODIFIED == GetCheckedRadioButton(IDC_RADIOORIGINAL, IDC_RADIOMODIFIED)));
  131. }
  132. else
  133. {
  134. ::EnableWindow(GetDlgItemHWND(IDC_RADIOMODIFIED), FALSE);
  135. ::EnableWindow(GetDlgItemHWND(IDC_RADIOORIGINAL), FALSE);
  136. }
  137. }
  138. }
  139. //-------------------------------------------------------------------------
  140. // Update the checkbox for pPage (indicated by nControlID) as well as
  141. // updating fAllNormal and fAllDiagnostic.
  142. //-------------------------------------------------------------------------
  143. void CPageGeneral::UpdateCheckBox(CPageBase * pPage, UINT nControlID, BOOL & fAllNormal, BOOL & fAllDiagnostic)
  144. {
  145. CPageBase::TabState state = pPage->GetCurrentTabState();
  146. UINT nCheck = BST_CHECKED;
  147. if (state == CPageBase::DIAGNOSTIC)
  148. nCheck = BST_UNCHECKED;
  149. else if (state == CPageBase::USER)
  150. nCheck = BST_INDETERMINATE;
  151. CheckDlgButton(nControlID, nCheck);
  152. // Finally, we need to keep track if all of the check boxes are either
  153. // NORMAL or DIAGNOSTIC.
  154. if (state != CPageBase::NORMAL)
  155. fAllNormal = FALSE;
  156. if (state != CPageBase::DIAGNOSTIC)
  157. fAllDiagnostic = FALSE;
  158. }
  159. //-------------------------------------------------------------------------
  160. // Allow another tab (OK, only the BOOT.INI tab will ever use this) to
  161. // force the selection of the Selective radio button.
  162. //-------------------------------------------------------------------------
  163. void CPageGeneral::ForceSelectiveRadio(BOOL fNewValue)
  164. {
  165. m_fForceSelectiveRadio = fNewValue;
  166. }
  167. //-------------------------------------------------------------------------
  168. // If the user clicks on the Startup or Diagnostic radio button, then
  169. // all of the tabs will receive the appropriate notification.
  170. //-------------------------------------------------------------------------
  171. void CPageGeneral::OnDiagnosticStartup()
  172. {
  173. m_fForceSelectiveRadio = FALSE;
  174. if (ppageSystemIni) dynamic_cast<CPageBase *>(ppageSystemIni)->SetDiagnostic();
  175. if (ppageWinIni) dynamic_cast<CPageBase *>(ppageWinIni)->SetDiagnostic();
  176. if (ppageBootIni) dynamic_cast<CPageBase *>(ppageBootIni)->SetDiagnostic();
  177. if (ppageServices) dynamic_cast<CPageBase *>(ppageServices)->SetDiagnostic();
  178. if (ppageStartup) dynamic_cast<CPageBase *>(ppageStartup)->SetDiagnostic();
  179. UpdateControls();
  180. }
  181. void CPageGeneral::OnNormalStartup()
  182. {
  183. m_fForceSelectiveRadio = FALSE;
  184. if (ppageSystemIni) dynamic_cast<CPageBase *>(ppageSystemIni)->SetNormal();
  185. if (ppageWinIni) dynamic_cast<CPageBase *>(ppageWinIni)->SetNormal();
  186. if (ppageBootIni) dynamic_cast<CPageBase *>(ppageBootIni)->SetNormal();
  187. if (ppageServices) dynamic_cast<CPageBase *>(ppageServices)->SetNormal();
  188. if (ppageStartup) dynamic_cast<CPageBase *>(ppageStartup)->SetNormal();
  189. UpdateControls();
  190. }
  191. //-------------------------------------------------------------------------
  192. // Most of the CPageBase functions we need to override (pure virtual)
  193. // shouldn't do anything at all.
  194. //-------------------------------------------------------------------------
  195. CPageBase::TabState CPageGeneral::GetCurrentTabState()
  196. {
  197. return NORMAL;
  198. }
  199. BOOL CPageGeneral::OnApply()
  200. {
  201. this->PostMessage(WM_SETCANCELTOCLOSE);
  202. return TRUE;
  203. }
  204. void CPageGeneral::CommitChanges()
  205. {
  206. }
  207. void CPageGeneral::SetNormal()
  208. {
  209. }
  210. void CPageGeneral::SetDiagnostic()
  211. {
  212. }
  213. //-------------------------------------------------------------------------
  214. // For some reason, CancelToClose() doesn't work if called in the
  215. // OnApply override. So that function posts a user message to this
  216. // page, which is handled by this function.
  217. //-------------------------------------------------------------------------
  218. LRESULT CPageGeneral::OnSetCancelToClose(WPARAM wparam, LPARAM lparam)
  219. {
  220. CancelToClose();
  221. return 0;
  222. }
  223. //-------------------------------------------------------------------------
  224. // If the user selects selective startup radio button, force the selection
  225. // to stick even if all the checkboxes are diagnostic or normal.
  226. //-------------------------------------------------------------------------
  227. void CPageGeneral::OnSelectiveStartup()
  228. {
  229. m_fForceSelectiveRadio = TRUE;
  230. UpdateControls();
  231. }
  232. //-------------------------------------------------------------------------
  233. // Handles the typical case for the checkbox click.
  234. //-------------------------------------------------------------------------
  235. void CPageGeneral::OnClickedCheckBox(CPageBase * pPage, UINT nControlID)
  236. {
  237. ASSERT(pPage);
  238. ASSERT(nControlID);
  239. UINT nCheck = IsDlgButtonChecked(nControlID);
  240. if (pPage != NULL)
  241. {
  242. switch (nCheck)
  243. {
  244. case BST_UNCHECKED:
  245. pPage->SetDiagnostic();
  246. break;
  247. case BST_INDETERMINATE:
  248. pPage->SetDiagnostic();
  249. break;
  250. case BST_CHECKED:
  251. pPage->SetNormal();
  252. break;
  253. }
  254. SetModified(TRUE);
  255. UpdateControls();
  256. }
  257. }
  258. //-------------------------------------------------------------------------
  259. // If the user clicks on a check box, we should allow the user
  260. // to toggle between DIAGNOSTIC and NORMAL.
  261. //-------------------------------------------------------------------------
  262. void CPageGeneral::OnCheckProcSysIni()
  263. {
  264. OnClickedCheckBox(ppageSystemIni, IDC_CHECK_PROCSYSINI);
  265. }
  266. void CPageGeneral::OnCheckStartupItems()
  267. {
  268. OnClickedCheckBox(ppageStartup, IDC_CHECKLOADSTARTUPITEMS);
  269. }
  270. void CPageGeneral::OnCheckServices()
  271. {
  272. OnClickedCheckBox(ppageServices, IDC_CHECKLOADSYSSERVICES);
  273. }
  274. void CPageGeneral::OnCheckWinIni()
  275. {
  276. OnClickedCheckBox(ppageWinIni, IDC_CHECKPROCWININI);
  277. }
  278. //-------------------------------------------------------------------------
  279. // Handle radio button selections for the BOOT.INI control.
  280. //-------------------------------------------------------------------------
  281. void CPageGeneral::OnRadioModified()
  282. {
  283. // The user can never actually select this radio button. If this option
  284. // is enabled, it's because it is already selected.
  285. }
  286. void CPageGeneral::OnRadioOriginal()
  287. {
  288. if (ppageBootIni)
  289. {
  290. dynamic_cast<CPageBase *>(ppageBootIni)->SetNormal();
  291. ::EnableWindow(GetDlgItemHWND(IDC_RADIOMODIFIED), FALSE);
  292. }
  293. UpdateControls();
  294. }
  295. //-------------------------------------------------------------------------
  296. // Display the extract dialog.
  297. //-------------------------------------------------------------------------
  298. void CPageGeneral::OnButtonExtract()
  299. {
  300. CExpandDlg dlg;
  301. dlg.DoModal();
  302. }
  303. //-------------------------------------------------------------------------
  304. // Launch System Restore, if it's around.
  305. //-------------------------------------------------------------------------
  306. void CPageGeneral::OnButtonSystemRestore()
  307. {
  308. TCHAR szPath[MAX_PATH];
  309. if (::ExpandEnvironmentStrings(_T("%windir%\\system32\\restore\\rstrui.exe"), szPath, MAX_PATH))
  310. ::ShellExecute(NULL, NULL, szPath, NULL, NULL, SW_SHOWNORMAL);
  311. }