Source code of Windows XP (NT5)
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.

308 lines
7.5 KiB

  1. /*++
  2. Copyright (C) 1998-1999 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. try
  98. {
  99. if (BST_CHECKED == IsDlgButtonChecked(m_hDlg, IDC_RESTART)) {
  100. //
  101. // Restart the computer
  102. //
  103. if (EnablePrivilege((PCTSTR)SE_SHUTDOWN_NAME, TRUE)) {
  104. ExitWindowsEx(EWX_REBOOT, 0);
  105. }
  106. }
  107. }
  108. catch (CMemoryException* e)
  109. {
  110. e->Delete();
  111. MsgBoxParam(m_hDlg, 0, 0, 0);
  112. }
  113. return CPropSheetPage::OnWizNext();
  114. }
  115. BOOL
  116. CTSEnableDeviceFinishPage::OnSetActive()
  117. {
  118. DWORD RestartFlags = m_pDevice->m_pMachine->DiGetFlags(*m_pDevice);
  119. SetDlgItemText(m_hDlg, IDC_TS_DRVDESC, m_pDevice->GetDisplayName());
  120. HICON hIconNew;
  121. hIconNew = m_pDevice->LoadClassIcon();
  122. if (hIconNew) {
  123. HICON hIconOld;
  124. m_IDCicon = IDC_CLASSICON; // Save for cleanup in OnDestroy.
  125. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLASSICON,
  126. STM_SETICON, (WPARAM)hIconNew,
  127. 0);
  128. if (hIconOld) {
  129. DestroyIcon(hIconOld);
  130. }
  131. }
  132. //
  133. // We need to restart the machine for the enable to take affect
  134. //
  135. if (RestartFlags & (DI_NEEDRESTART | DI_NEEDREBOOT)) {
  136. String strAltText_1;
  137. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_RESTART);
  138. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  139. ::SendMessage(GetControl(IDC_RESTART), BM_SETCHECK, BST_CHECKED, 0);
  140. //
  141. // We don't need to restart
  142. //
  143. } else {
  144. DWORD Problem, Status;
  145. Problem = Status = 0;
  146. m_pDevice->GetStatus(&Status, &Problem);
  147. //
  148. // The device is still disabled
  149. //
  150. if (CM_PROB_DISABLED == Problem) {
  151. String strAltText_1;
  152. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_FAIL);
  153. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  154. //
  155. // The device has some other problem
  156. //
  157. } else if (Problem) {
  158. String strAltText_1;
  159. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_PROBLEM);
  160. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  161. //
  162. // The device is now working
  163. //
  164. } else {
  165. String strAltText_1;
  166. strAltText_1.LoadString(g_hInstance, IDS_TS_ENABLEDEVICE_SUCCESS);
  167. SetDlgItemText(m_hDlg, IDC_TS_ENABLEDEVICE_FINISH_MSG, strAltText_1);
  168. }
  169. ::ShowWindow(GetControl(IDC_RESTART), SW_HIDE);
  170. }
  171. PropSheet_SetWizButtons(GetParent(m_hDlg), PSWIZB_FINISH);
  172. ::EnableWindow(GetDlgItem(GetParent(m_hDlg), IDCANCEL), FALSE);
  173. return CPropSheetPage::OnSetActive();
  174. }
  175. HPROPSHEETPAGE
  176. CTSRestartComputerFinishPage::Create(
  177. CDevice* pDevice
  178. )
  179. {
  180. if (!m_pDevice)
  181. {
  182. ASSERT(pDevice);
  183. m_pDevice = pDevice;
  184. m_psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  185. m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TS_RESTART_FINISH);
  186. m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_TS_RESTART_FINISH_INFO);
  187. m_psp.pszTitle = MAKEINTRESOURCE(IDS_TROUBLESHOOTING_NAME);
  188. m_psp.lParam = (LPARAM)this;
  189. DWORD Problem, Status;
  190. if (pDevice->GetStatus(&Status, &Problem))
  191. {
  192. m_Problem = Problem;
  193. return CPropSheetPage::CreatePage();
  194. }
  195. }
  196. return NULL;
  197. }
  198. BOOL
  199. CTSRestartComputerFinishPage::OnWizFinish()
  200. {
  201. try
  202. {
  203. if (BST_CHECKED == IsDlgButtonChecked(m_hDlg, IDC_RESTART)) {
  204. //
  205. // Restart the computer
  206. //
  207. if (EnablePrivilege((PCTSTR)SE_SHUTDOWN_NAME, TRUE)) {
  208. ExitWindowsEx(EWX_REBOOT, 0);
  209. }
  210. }
  211. }
  212. catch (CMemoryException* e)
  213. {
  214. e->Delete();
  215. MsgBoxParam(m_hDlg, 0, 0, 0);
  216. }
  217. return CPropSheetPage::OnWizNext();
  218. }
  219. BOOL
  220. CTSRestartComputerFinishPage::OnSetActive()
  221. {
  222. SetDlgItemText(m_hDlg, IDC_TS_DRVDESC, m_pDevice->GetDisplayName());
  223. HICON hIconNew;
  224. hIconNew = m_pDevice->LoadClassIcon();
  225. if (hIconNew) {
  226. HICON hIconOld;
  227. m_IDCicon = IDC_CLASSICON; // Save for cleanup in OnDestroy.
  228. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLASSICON,
  229. STM_SETICON, (WPARAM)hIconNew,
  230. 0);
  231. if (hIconOld) {
  232. DestroyIcon(hIconOld);
  233. }
  234. }
  235. ::SendMessage(GetControl(IDC_RESTART), BM_SETCHECK, BST_CHECKED, 0);
  236. PropSheet_SetWizButtons(GetParent(m_hDlg), PSWIZB_FINISH);
  237. return CPropSheetPage::OnSetActive();
  238. }