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.

290 lines
7.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. tsmisc.cpp
  5. Abstract:
  6. This module implements Device Manager troubleshooting supporting classes
  7. Author:
  8. Jason Cobb (jasonc) created
  9. Revision History:
  10. --*/
  11. #include "devmgr.h"
  12. #include "proppage.h"
  13. #include "tsmisc.h"
  14. #include "tswizard.h"
  15. HPROPSHEETPAGE
  16. CTSEnableDeviceIntroPage::Create(
  17. CDevice* pDevice
  18. )
  19. {
  20. if (!m_pDevice)
  21. {
  22. ASSERT(pDevice);
  23. m_pDevice = pDevice;
  24. m_psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  25. m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TS_ENABLE);
  26. m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_TS_ENABLE_INFO);
  27. m_psp.pszTitle = MAKEINTRESOURCE(IDS_TROUBLESHOOTING_NAME);
  28. m_psp.lParam = (LPARAM)this;
  29. DWORD Problem, Status;
  30. if (pDevice->GetStatus(&Status, &Problem))
  31. {
  32. m_Problem = Problem;
  33. return CPropSheetPage::CreatePage();
  34. }
  35. }
  36. return NULL;
  37. }
  38. BOOL
  39. CTSEnableDeviceIntroPage::OnWizNext()
  40. {
  41. try
  42. {
  43. m_pDevice->EnableDisableDevice(m_hDlg, TRUE);
  44. }
  45. catch (CMemoryException* e)
  46. {
  47. e->Delete();
  48. MsgBoxParam(m_hDlg, 0, 0, 0);
  49. }
  50. return CPropSheetPage::OnWizNext();
  51. }
  52. BOOL
  53. CTSEnableDeviceIntroPage::OnSetActive()
  54. {
  55. SetDlgItemText(m_hDlg, IDC_TS_DRVDESC, m_pDevice->GetDisplayName());
  56. HICON hIconNew;
  57. hIconNew = m_pDevice->LoadClassIcon();
  58. if (hIconNew) {
  59. HICON hIconOld;
  60. m_IDCicon = IDC_CLASSICON; // Save for cleanup in OnDestroy.
  61. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLASSICON,
  62. STM_SETICON, (WPARAM)hIconNew,
  63. 0);
  64. if (hIconOld) {
  65. DestroyIcon(hIconOld);
  66. }
  67. }
  68. PropSheet_SetWizButtons(GetParent(m_hDlg), PSWIZB_NEXT);
  69. return CPropSheetPage::OnSetActive();
  70. }
  71. HPROPSHEETPAGE
  72. CTSEnableDeviceFinishPage::Create(
  73. CDevice* pDevice
  74. )
  75. {
  76. if (!m_pDevice)
  77. {
  78. ASSERT(pDevice);
  79. m_pDevice = pDevice;
  80. m_psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  81. m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TS_ENABLE_FINISH);
  82. m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_TS_ENABLE_FINISH_INFO);
  83. m_psp.pszTitle = MAKEINTRESOURCE(IDS_TROUBLESHOOTING_NAME);
  84. m_psp.lParam = (LPARAM)this;
  85. DWORD Problem, Status;
  86. if (pDevice->GetStatus(&Status, &Problem))
  87. {
  88. m_Problem = Problem;
  89. return CPropSheetPage::CreatePage();
  90. }
  91. }
  92. return NULL;
  93. }
  94. BOOL
  95. CTSEnableDeviceFinishPage::OnWizFinish()
  96. {
  97. if (BST_CHECKED == IsDlgButtonChecked(m_hDlg, IDC_RESTART)) {
  98. //
  99. // Restart the computer
  100. //
  101. if (pSetupEnablePrivilege(SE_SHUTDOWN_NAME, TRUE)) {
  102. ExitWindowsEx(EWX_REBOOT, REASON_PLANNED_FLAG | REASON_HWINSTALL);
  103. }
  104. }
  105. return CPropSheetPage::OnWizFinish();
  106. }
  107. BOOL
  108. CTSEnableDeviceFinishPage::OnSetActive()
  109. {
  110. DWORD RestartFlags = m_pDevice->m_pMachine->DiGetFlags(*m_pDevice);
  111. SetDlgItemText(m_hDlg, IDC_TS_DRVDESC, m_pDevice->GetDisplayName());
  112. HICON hIconNew;
  113. hIconNew = m_pDevice->LoadClassIcon();
  114. if (hIconNew) {
  115. HICON hIconOld;
  116. m_IDCicon = IDC_CLASSICON; // Save for cleanup in OnDestroy.
  117. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLASSICON,
  118. STM_SETICON, (WPARAM)hIconNew,
  119. 0);
  120. if (hIconOld) {
  121. DestroyIcon(hIconOld);
  122. }
  123. }
  124. //
  125. // We need to restart the machine for the enable to take affect
  126. //
  127. if (RestartFlags & (DI_NEEDRESTART | DI_NEEDREBOOT)) {
  128. String strAltText_1;
  129. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_RESTART);
  130. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  131. ::SendMessage(GetControl(IDC_RESTART), BM_SETCHECK, BST_CHECKED, 0);
  132. //
  133. // We don't need to restart
  134. //
  135. } else {
  136. DWORD Problem, Status;
  137. Problem = Status = 0;
  138. m_pDevice->GetStatus(&Status, &Problem);
  139. //
  140. // The device is still disabled
  141. //
  142. if (CM_PROB_DISABLED == Problem) {
  143. String strAltText_1;
  144. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_FAIL);
  145. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  146. //
  147. // The device has some other problem
  148. //
  149. } else if (Problem) {
  150. String strAltText_1;
  151. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_PROBLEM);
  152. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  153. //
  154. // The device is now working
  155. //
  156. } else {
  157. String strAltText_1;
  158. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_SUCCESS);
  159. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  160. }
  161. ::ShowWindow(GetControl(IDC_RESTART), SW_HIDE);
  162. }
  163. PropSheet_SetWizButtons(GetParent(m_hDlg), PSWIZB_FINISH);
  164. ::EnableWindow(GetDlgItem(GetParent(m_hDlg), IDCANCEL), FALSE);
  165. return CPropSheetPage::OnSetActive();
  166. }
  167. HPROPSHEETPAGE
  168. CTSRestartComputerFinishPage::Create(
  169. CDevice* pDevice
  170. )
  171. {
  172. if (!m_pDevice)
  173. {
  174. ASSERT(pDevice);
  175. m_pDevice = pDevice;
  176. m_psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  177. m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TS_RESTART_FINISH);
  178. m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_TS_RESTART_FINISH_INFO);
  179. m_psp.pszTitle = MAKEINTRESOURCE(IDS_TROUBLESHOOTING_NAME);
  180. m_psp.lParam = (LPARAM)this;
  181. DWORD Problem, Status;
  182. if (pDevice->GetStatus(&Status, &Problem))
  183. {
  184. m_Problem = Problem;
  185. return CPropSheetPage::CreatePage();
  186. }
  187. }
  188. return NULL;
  189. }
  190. BOOL
  191. CTSRestartComputerFinishPage::OnWizFinish()
  192. {
  193. if (BST_CHECKED == IsDlgButtonChecked(m_hDlg, IDC_RESTART)) {
  194. //
  195. // Restart the computer
  196. //
  197. if (pSetupEnablePrivilege(SE_SHUTDOWN_NAME, TRUE)) {
  198. ExitWindowsEx(EWX_REBOOT, REASON_PLANNED_FLAG | REASON_HWINSTALL);
  199. }
  200. }
  201. return CPropSheetPage::OnWizFinish();
  202. }
  203. BOOL
  204. CTSRestartComputerFinishPage::OnSetActive()
  205. {
  206. SetDlgItemText(m_hDlg, IDC_TS_DRVDESC, m_pDevice->GetDisplayName());
  207. HICON hIconNew;
  208. hIconNew = m_pDevice->LoadClassIcon();
  209. if (hIconNew) {
  210. HICON hIconOld;
  211. m_IDCicon = IDC_CLASSICON; // Save for cleanup in OnDestroy.
  212. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLASSICON,
  213. STM_SETICON, (WPARAM)hIconNew,
  214. 0);
  215. if (hIconOld) {
  216. DestroyIcon(hIconOld);
  217. }
  218. }
  219. ::SendMessage(GetControl(IDC_RESTART), BM_SETCHECK, BST_CHECKED, 0);
  220. PropSheet_SetWizButtons(GetParent(m_hDlg), PSWIZB_FINISH);
  221. return CPropSheetPage::OnSetActive();
  222. }