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.

357 lines
6.8 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1997 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. hardware.c
  7. Abstract:
  8. Implements the Hardware tab of the System Control Panel Applet
  9. Author:
  10. William Hsieh (williamh) 03-Jul-1997
  11. Revision History:
  12. 17-Oct-1997 scotthal
  13. Complete overhaul
  14. --*/
  15. #include "sysdm.h"
  16. //
  17. // Help IDs
  18. //
  19. DWORD aHardwareHelpIds[] = {
  20. IDC_WIZARD_ICON, (IDH_HARDWARE + 0),
  21. IDC_WIZARD_TEXT, (IDH_HARDWARE + 0),
  22. IDC_WIZARD_START, (IDH_HARDWARE + 1),
  23. IDC_DEVMGR_ICON, (IDH_HARDWARE + 2),
  24. IDC_DEVMGR_TEXT, (IDH_HARDWARE + 2),
  25. IDC_DEVMGR_START, (IDH_HARDWARE + 3),
  26. IDC_HWPROFILES_ICON, (IDH_HARDWARE + 4),
  27. IDC_HWPROFILES_START_TEXT, (IDH_HARDWARE + 4),
  28. IDC_HWPROFILES_START, (IDH_HARDWARE + 5),
  29. IDC_DRIVER_SIGNING, (IDH_HARDWARE + 6),
  30. 0, 0
  31. };
  32. //
  33. // Function prototypes
  34. //
  35. void
  36. InitHardwareDlg(
  37. IN HWND hDlg
  38. );
  39. BOOL
  40. HardwareHandleCommand(
  41. IN HWND hDlg,
  42. IN WPARAM wParam,
  43. IN LPARAM lParam
  44. );
  45. void
  46. StartHardwareWizard(
  47. IN HWND hDlg
  48. );
  49. void
  50. StartDeviceManager(
  51. IN HWND hDlg
  52. );
  53. typedef HRESULT (WINAPI *PFNDRIVERSIGNING)(HWND hwnd, DWORD dwFlags);
  54. BOOL ShowDriverSigning(HWND hDlg)
  55. {
  56. BOOL bFound = FALSE;
  57. HMODULE hmod = LoadLibrary(TEXT("sigtab.dll"));
  58. if (hmod)
  59. {
  60. PFNDRIVERSIGNING pfn = (PFNDRIVERSIGNING)GetProcAddress(hmod, "DriverSigningDialog");
  61. if (pfn)
  62. {
  63. bFound = TRUE;
  64. if (hDlg)
  65. pfn(hDlg, 0);
  66. }
  67. FreeLibrary(hmod);
  68. }
  69. return bFound;
  70. }
  71. VOID
  72. InitHardwareDlg(
  73. IN HWND hDlg
  74. )
  75. /*++
  76. Routine Description:
  77. Initialize the hardware page
  78. Arguments:
  79. hDlg -
  80. Supplies the window handle
  81. Return Value:
  82. None
  83. --*/
  84. {
  85. HICON hIconNew;
  86. HICON hIconOld;
  87. hIconNew = ExtractIcon(hInstance, WIZARD_FILENAME, 0);
  88. if (hIconNew && (HICON)1 != hIconNew) {
  89. hIconOld = (HICON)SendDlgItemMessage(hDlg, IDC_WIZARD_ICON, STM_SETICON, (WPARAM)hIconNew, 0);
  90. if(hIconOld) {
  91. DestroyIcon(hIconOld);
  92. }
  93. }
  94. hIconNew = ExtractIcon(hInstance, DEVMGR_FILENAME, 0);
  95. if (hIconNew && (HICON)1 != hIconNew) {
  96. hIconOld = (HICON)SendDlgItemMessage(hDlg, IDC_DEVMGR_ICON, STM_SETICON, (WPARAM)hIconNew, 0);
  97. if(hIconOld) {
  98. DestroyIcon(hIconOld);
  99. }
  100. }
  101. if (!ShowDriverSigning(NULL))
  102. ShowWindow(GetDlgItem(hDlg, IDC_DRIVER_SIGNING), SW_HIDE);
  103. }
  104. INT_PTR
  105. APIENTRY
  106. HardwareDlgProc(
  107. IN HWND hDlg,
  108. IN UINT uMsg,
  109. IN WPARAM wParam,
  110. IN LPARAM lParam
  111. )
  112. /*++
  113. Routine Description:
  114. Handles messages sent to the hardware tab
  115. Arguments:
  116. hDlg -
  117. Supplies window handle
  118. uMsg -
  119. Supplies message being sent
  120. wParam -
  121. Supplies message parameter
  122. lParam -
  123. Supplies message parameter
  124. Return Value:
  125. TRUE if message was handled
  126. FALSE if message was unhandled
  127. --*/
  128. {
  129. switch (uMsg) {
  130. case WM_INITDIALOG:
  131. InitHardwareDlg(hDlg);
  132. break;
  133. case WM_COMMAND:
  134. return HardwareHandleCommand(hDlg, wParam, lParam);
  135. break;
  136. case WM_HELP: // F1
  137. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP, (DWORD_PTR) (LPSTR) aHardwareHelpIds);
  138. break;
  139. case WM_CONTEXTMENU: // right mouse click
  140. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU, (DWORD_PTR) (LPSTR) aHardwareHelpIds);
  141. break;
  142. default:
  143. return(FALSE);
  144. } // switch
  145. return(TRUE);
  146. }
  147. BOOL
  148. HardwareHandleCommand(
  149. IN HWND hDlg,
  150. IN WPARAM wParam,
  151. IN LPARAM lParam
  152. )
  153. /*++
  154. Routine Description:
  155. Handles WM_COMMAND messages sent to the Hardware tab
  156. Arguments:
  157. hDlg -
  158. Supplies the window handle
  159. wParam -
  160. Supplies message parameter
  161. lParam -
  162. Supplies message parameter
  163. Return Value:
  164. TRUE if message was handled
  165. FALSE if message was unhandled
  166. --*/
  167. {
  168. DWORD_PTR dwResult = 0;
  169. switch (LOWORD(wParam)) {
  170. case IDC_WIZARD_START:
  171. StartHardwareWizard(hDlg);
  172. break;
  173. case IDC_DEVMGR_START:
  174. StartDeviceManager(hDlg);
  175. break;
  176. case IDC_DRIVER_SIGNING:
  177. ShowDriverSigning(hDlg);
  178. break;
  179. case IDC_HWPROFILES_START:
  180. dwResult = DialogBox(
  181. hInstance,
  182. MAKEINTRESOURCE(DLG_HWPROFILES),
  183. hDlg,
  184. HardwareProfilesDlg
  185. );
  186. break;
  187. default:
  188. return(FALSE);
  189. } // switch
  190. return(TRUE);
  191. }
  192. void
  193. StartHardwareWizard(
  194. IN HWND hDlg
  195. )
  196. /*++
  197. Routine Description:
  198. Start the Hardware wizard
  199. Arguments:
  200. hDlg -
  201. Supplies window handle
  202. Return Value:
  203. None
  204. --*/
  205. {
  206. TCHAR szWizardPath[MAX_PATH];
  207. if (GetSystemDirectory(szWizardPath, ARRAYSIZE(szWizardPath)) &&
  208. PathAppend(szWizardPath, WIZARD_FILENAME))
  209. {
  210. SHELLEXECUTEINFO sei = {0};
  211. sei.cbSize = sizeof(sei);
  212. sei.hwnd = hDlg;
  213. sei.lpFile = szWizardPath;
  214. sei.lpParameters = WIZARD_PARAMETERS;
  215. sei.lpVerb = WIZARD_VERB;
  216. sei.nShow = SW_NORMAL;
  217. sei.hInstApp = hInstance;
  218. if (!ShellExecuteEx(&sei))
  219. {
  220. if (ERROR_FILE_NOT_FOUND == GetLastError() ||
  221. ERROR_PATH_NOT_FOUND == GetLastError())
  222. {
  223. // reinitialize the contents of the dialog in case
  224. // user has fixed the problem
  225. InitHardwareDlg(hDlg);
  226. }
  227. }
  228. }
  229. }
  230. void
  231. StartDeviceManager(
  232. IN HWND hDlg
  233. )
  234. /*++
  235. Routine Description:
  236. Start Device Manager
  237. Arguments:
  238. hDlg -
  239. Supplies window handle
  240. Return Value:
  241. None
  242. --*/
  243. {
  244. HINSTANCE hDevMgr;
  245. PDEVMGR_EXECUTE_PROC DevMgrProc;
  246. hDevMgr = LoadLibrary(DEVMGR_FILENAME);
  247. if (hDevMgr)
  248. {
  249. HourGlass(TRUE);
  250. DevMgrProc = (PDEVMGR_EXECUTE_PROC) GetProcAddress(hDevMgr, DEVMGR_EXECUTE_PROC_NAME);
  251. if (DevMgrProc)
  252. (*DevMgrProc)(hDlg, hInstance, NULL, SW_NORMAL);
  253. else
  254. MsgBoxParam(hDlg, IDS_SYSDM_NOEXPORTS_DEVMANPROG, IDS_SYSDM_TITLE, MB_OK | MB_ICONEXCLAMATION, DEVMGR_FILENAME);
  255. FreeLibrary(hDevMgr);
  256. HourGlass(FALSE);
  257. }
  258. else
  259. {
  260. MsgBoxParam(hDlg, IDS_SYSDM_NOLOAD_DEVMANPROG, IDS_SYSDM_TITLE, MB_OK | MB_ICONEXCLAMATION, DEVMGR_FILENAME);
  261. }
  262. }