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.

940 lines
33 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation
  6. //
  7. // File: selclass.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "hdwwiz.h"
  11. int CALLBACK
  12. ClassListCompare(
  13. LPARAM lParam1,
  14. LPARAM lParam2,
  15. LPARAM lParamSort
  16. )
  17. {
  18. TCHAR ClassDescription1[LINE_LEN];
  19. TCHAR ClassDescription2[LINE_LEN];
  20. UNREFERENCED_PARAMETER(lParamSort);
  21. //
  22. // Check if the 1st item is GUID_DEVCLASS_UNKNOWN
  23. //
  24. if (IsEqualGUID((LPGUID)lParam1, &GUID_DEVCLASS_UNKNOWN)) {
  25. return -1;
  26. }
  27. //
  28. // Check if the 2nd item is GUID_DEVCLASS_UNKNOWN
  29. //
  30. if (IsEqualGUID((LPGUID)lParam2, &GUID_DEVCLASS_UNKNOWN)) {
  31. return 1;
  32. }
  33. if (SetupDiGetClassDescription((LPGUID)lParam1,
  34. ClassDescription1,
  35. LINE_LEN,
  36. NULL
  37. ) &&
  38. SetupDiGetClassDescription((LPGUID)lParam2,
  39. ClassDescription2,
  40. LINE_LEN,
  41. NULL
  42. )) {
  43. return (lstrcmpi(ClassDescription1, ClassDescription2));
  44. }
  45. return 0;
  46. }
  47. void InitHDW_PickClassDlg(
  48. HWND hwndClassList,
  49. PHARDWAREWIZ HardwareWiz
  50. )
  51. {
  52. LPGUID ClassGuid, lpClassGuidSelected;
  53. GUID ClassGuidSelected;
  54. int lvIndex;
  55. DWORD ClassGuidNum;
  56. LV_ITEM lviItem;
  57. TCHAR ClassDescription[LINE_LEN];
  58. SendMessage(hwndClassList, WM_SETREDRAW, FALSE, 0L);
  59. // Clear the Class List
  60. ListView_DeleteAllItems(hwndClassList);
  61. lviItem.mask = LVIF_TEXT | LVIF_PARAM;
  62. lviItem.iItem = -1;
  63. lviItem.iSubItem = 0;
  64. ClassGuid = HardwareWiz->ClassGuidList;
  65. ClassGuidNum = HardwareWiz->ClassGuidNum;
  66. // keep track of previosuly selected item
  67. if (IsEqualGUID(&HardwareWiz->lvClassGuidSelected, &GUID_NULL)) {
  68. lpClassGuidSelected = NULL;
  69. } else {
  70. ClassGuidSelected = HardwareWiz->lvClassGuidSelected;
  71. HardwareWiz->lvClassGuidSelected = GUID_NULL;
  72. lpClassGuidSelected = &ClassGuidSelected;
  73. }
  74. while (ClassGuidNum--) {
  75. if (SetupDiGetClassDescription(ClassGuid,
  76. ClassDescription,
  77. LINE_LEN,
  78. NULL
  79. )) {
  80. if (IsEqualGUID(ClassGuid, &GUID_DEVCLASS_UNKNOWN)) {
  81. //
  82. // We need to special case the UNKNOWN class and to give it a
  83. // special icon (blank) and special text (Show All Devices).
  84. //
  85. LoadString(hHdwWiz,
  86. IDS_SHOWALLDEVICES,
  87. ClassDescription,
  88. SIZECHARS(ClassDescription)
  89. );
  90. lviItem.iImage = g_BlankIconIndex;
  91. lviItem.mask |= LVIF_IMAGE;
  92. } else if (SetupDiGetClassImageIndex(&HardwareWiz->ClassImageList,
  93. ClassGuid,
  94. &lviItem.iImage
  95. )) {
  96. lviItem.mask |= LVIF_IMAGE;
  97. } else {
  98. lviItem.mask &= ~LVIF_IMAGE;
  99. }
  100. lviItem.pszText = ClassDescription;
  101. lviItem.lParam = (LPARAM) ClassGuid;
  102. lvIndex = ListView_InsertItem(hwndClassList, &lviItem);
  103. //
  104. // check for previous selection
  105. //
  106. if (lpClassGuidSelected &&
  107. IsEqualGUID(lpClassGuidSelected, ClassGuid)) {
  108. ListView_SetItemState(hwndClassList,
  109. lvIndex,
  110. LVIS_SELECTED|LVIS_FOCUSED,
  111. LVIS_SELECTED|LVIS_FOCUSED
  112. );
  113. lpClassGuidSelected = NULL;
  114. }
  115. }
  116. ClassGuid++;
  117. }
  118. //
  119. // Sort the list
  120. //
  121. ListView_SortItems(hwndClassList, (PFNLVCOMPARE)ClassListCompare, NULL);
  122. //
  123. // if previous selection wasn't found select first in list.
  124. //
  125. if (IsEqualGUID(&HardwareWiz->lvClassGuidSelected, &GUID_NULL)) {
  126. lvIndex = 0;
  127. ListView_SetItemState(hwndClassList,
  128. lvIndex,
  129. LVIS_SELECTED|LVIS_FOCUSED,
  130. LVIS_SELECTED|LVIS_FOCUSED
  131. );
  132. }
  133. //
  134. // previous selection was found, fetch its current index
  135. //
  136. else {
  137. lvIndex = ListView_GetNextItem(hwndClassList,
  138. -1,
  139. LVNI_SELECTED
  140. );
  141. }
  142. //
  143. // scroll the selected item into view.
  144. //
  145. ListView_EnsureVisible(hwndClassList, lvIndex, FALSE);
  146. ListView_SetColumnWidth(hwndClassList, 0, LVSCW_AUTOSIZE_USEHEADER);
  147. SendMessage(hwndClassList, WM_SETREDRAW, TRUE, 0L);
  148. }
  149. INT_PTR CALLBACK
  150. HdwPickClassDlgProc(
  151. HWND hDlg,
  152. UINT wMsg,
  153. WPARAM wParam,
  154. LPARAM lParam
  155. )
  156. {
  157. HWND hwndClassList = GetDlgItem(hDlg, IDC_HDW_PICKCLASS_CLASSLIST);
  158. HWND hwndParentDlg = GetParent(hDlg);
  159. PHARDWAREWIZ HardwareWiz = (PHARDWAREWIZ)GetWindowLongPtr(hDlg, DWLP_USER);
  160. switch (wMsg) {
  161. case WM_INITDIALOG: {
  162. LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
  163. LV_COLUMN lvcCol;
  164. HardwareWiz = (PHARDWAREWIZ)lppsp->lParam;
  165. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)HardwareWiz);
  166. //
  167. // Get the Class Icon Image Lists. We do this only the first
  168. // time this dialog is initialized.
  169. //
  170. if (HardwareWiz->ClassImageList.cbSize) {
  171. ListView_SetImageList(hwndClassList,
  172. HardwareWiz->ClassImageList.ImageList,
  173. LVSIL_SMALL
  174. );
  175. }
  176. // Insert a column for the class list
  177. lvcCol.mask = LVCF_FMT | LVCF_WIDTH;
  178. lvcCol.fmt = LVCFMT_LEFT;
  179. lvcCol.iSubItem = 0;
  180. ListView_InsertColumn(hwndClassList, 0, (LV_COLUMN FAR *)&lvcCol);
  181. //
  182. // Save the class before the user chooses one. This will be restored
  183. // in the event the install is cancelled.
  184. //
  185. HardwareWiz->SavedClassGuid = HardwareWiz->DeviceInfoData.ClassGuid;
  186. break;
  187. }
  188. case WM_DESTROY:
  189. break;
  190. case WM_NOTIFY:
  191. switch (((NMHDR FAR *)lParam)->code) {
  192. //
  193. // This dialog is being activated. Each time we are activated
  194. // we free up the current DeviceInfo and create a new one. Although
  195. // inefficient, its necessary to reenumerate the class list.
  196. //
  197. case PSN_SETACTIVE:
  198. PropSheet_SetWizButtons(hwndParentDlg, PSWIZB_BACK | PSWIZB_NEXT);
  199. HardwareWiz->PrevPage = IDD_ADDDEVICE_SELECTCLASS;
  200. //
  201. // If we have DeviceInfo from going forward delete it.
  202. //
  203. if (HardwareWiz->ClassGuidSelected) {
  204. SetupDiDeleteDeviceInfo(HardwareWiz->hDeviceInfo, &HardwareWiz->DeviceInfoData);
  205. memset(&HardwareWiz->DeviceInfoData, 0, sizeof(SP_DEVINFO_DATA));
  206. }
  207. HardwareWiz->ClassGuidSelected = NULL;
  208. HdwBuildClassInfoList(HardwareWiz,
  209. DIBCI_NOINSTALLCLASS
  210. );
  211. InitHDW_PickClassDlg(hwndClassList, HardwareWiz);
  212. break;
  213. case PSN_RESET:
  214. break;
  215. case PSN_WIZBACK:
  216. HardwareWiz->PrevPage = IDD_ADDDEVICE_SELECTCLASS;
  217. if (HardwareWiz->EnterInto == IDD_ADDDEVICE_SELECTCLASS) {
  218. SetDlgMsgResult(hDlg, wMsg, HardwareWiz->EnterFrom);
  219. } else {
  220. SetDlgMsgResult(hDlg, wMsg, IDD_ADDDEVICE_ASKDETECT);
  221. }
  222. break;
  223. case PSN_WIZNEXT: {
  224. LPGUID ClassGuidSelected;
  225. SetDlgMsgResult(hDlg, wMsg, IDD_ADDDEVICE_SELECTDEVICE);
  226. if (IsEqualGUID(&HardwareWiz->lvClassGuidSelected, &GUID_NULL)) {
  227. HardwareWiz->ClassGuidSelected = NULL;
  228. break;
  229. }
  230. ClassGuidSelected = &HardwareWiz->lvClassGuidSelected;
  231. HardwareWiz->ClassGuidSelected = ClassGuidSelected;
  232. //
  233. // Add a new element to the DeviceInfo from the GUID and class name
  234. //
  235. HardwareWiz->DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  236. if (!SetupDiGetClassDescription(HardwareWiz->ClassGuidSelected,
  237. HardwareWiz->ClassDescription,
  238. SIZECHARS(HardwareWiz->ClassDescription),
  239. NULL
  240. )
  241. ||
  242. !SetupDiClassNameFromGuid(HardwareWiz->ClassGuidSelected,
  243. HardwareWiz->ClassName,
  244. SIZECHARS(HardwareWiz->ClassName),
  245. NULL
  246. ))
  247. {
  248. // unhandled error!
  249. HardwareWiz->ClassGuidSelected = NULL;
  250. break;
  251. }
  252. if (IsEqualGUID(HardwareWiz->ClassGuidSelected, &GUID_DEVCLASS_UNKNOWN)) {
  253. ClassGuidSelected = (LPGUID)&GUID_NULL;
  254. }
  255. if (!SetupDiCreateDeviceInfo(HardwareWiz->hDeviceInfo,
  256. HardwareWiz->ClassName,
  257. ClassGuidSelected,
  258. NULL,
  259. hwndParentDlg,
  260. DICD_GENERATE_ID,
  261. &HardwareWiz->DeviceInfoData
  262. )
  263. ||
  264. !SetupDiSetSelectedDevice(HardwareWiz->hDeviceInfo,
  265. &HardwareWiz->DeviceInfoData
  266. ))
  267. {
  268. HardwareWiz->ClassGuidSelected = NULL;
  269. break;
  270. }
  271. break;
  272. }
  273. case NM_DBLCLK:
  274. PropSheet_PressButton(hwndParentDlg, PSBTN_NEXT);
  275. break;
  276. case LVN_ITEMCHANGED: {
  277. LPNM_LISTVIEW lpnmlv = (LPNM_LISTVIEW)lParam;
  278. if ((lpnmlv->uChanged & LVIF_STATE)) {
  279. if (lpnmlv->uNewState & LVIS_SELECTED) {
  280. HardwareWiz->lvClassGuidSelected = *((LPGUID)lpnmlv->lParam);
  281. } else if (IsEqualGUID((LPGUID)lpnmlv->lParam, &HardwareWiz->lvClassGuidSelected)) {
  282. HardwareWiz->lvClassGuidSelected = GUID_NULL;
  283. }
  284. }
  285. break;
  286. }
  287. }
  288. break;
  289. case WM_SYSCOLORCHANGE:
  290. _OnSysColorChange(hDlg, wParam, lParam);
  291. // Update the ImageList Background color
  292. ImageList_SetBkColor((HIMAGELIST)SendMessage(GetDlgItem(hDlg, IDC_HDW_PICKCLASS_CLASSLIST), LVM_GETIMAGELIST, (WPARAM)(LVSIL_SMALL), 0L),
  293. GetSysColor(COLOR_WINDOW));
  294. break;
  295. default:
  296. return(FALSE);
  297. }
  298. return(TRUE);
  299. }
  300. void
  301. DestroyDynamicWizard(
  302. HWND hwndParentDlg,
  303. PHARDWAREWIZ HardwareWiz,
  304. BOOL WmDestroy
  305. )
  306. {
  307. DWORD Pages;
  308. PSP_INSTALLWIZARD_DATA InstallWizard = &HardwareWiz->InstallDynaWiz;
  309. SP_DEVINSTALL_PARAMS DeviceInstallParams;
  310. Pages = InstallWizard->NumDynamicPages;
  311. InstallWizard->NumDynamicPages = 0;
  312. if (InstallWizard->DynamicPageFlags & DYNAWIZ_FLAG_PAGESADDED) {
  313. if (!WmDestroy) {
  314. while (Pages--) {
  315. PropSheet_RemovePage(hwndParentDlg,
  316. (WPARAM)-1,
  317. InstallWizard->DynamicPages[Pages]
  318. );
  319. InstallWizard->DynamicPages[Pages] = NULL;
  320. }
  321. }
  322. DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  323. if (SetupDiGetDeviceInstallParams(HardwareWiz->hDeviceInfo,
  324. &HardwareWiz->DeviceInfoData,
  325. &DeviceInstallParams
  326. ))
  327. {
  328. DeviceInstallParams.Flags |= DI_CLASSINSTALLPARAMS;
  329. SetupDiSetDeviceInstallParams(HardwareWiz->hDeviceInfo,
  330. &HardwareWiz->DeviceInfoData,
  331. &DeviceInstallParams
  332. );
  333. }
  334. InstallWizard->DynamicPageFlags &= ~DYNAWIZ_FLAG_PAGESADDED;
  335. InstallWizard->ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  336. InstallWizard->ClassInstallHeader.InstallFunction = DIF_DESTROYWIZARDDATA;
  337. InstallWizard->hwndWizardDlg = hwndParentDlg;
  338. if (SetupDiSetClassInstallParams(HardwareWiz->hDeviceInfo,
  339. &HardwareWiz->DeviceInfoData,
  340. &InstallWizard->ClassInstallHeader,
  341. sizeof(SP_INSTALLWIZARD_DATA)
  342. ))
  343. {
  344. SetupDiCallClassInstaller(DIF_DESTROYWIZARDDATA,
  345. HardwareWiz->hDeviceInfo,
  346. &HardwareWiz->DeviceInfoData
  347. );
  348. }
  349. }
  350. if (!WmDestroy) {
  351. }
  352. }
  353. //
  354. // The real select device page is in either setupapi or the class installer
  355. // for dyanwiz. this page is a blank page which never shows its face
  356. // to have a consistent place to jump to when the class is known.
  357. //
  358. INT_PTR CALLBACK
  359. HdwSelectDeviceDlgProc(
  360. HWND hDlg,
  361. UINT wMsg,
  362. WPARAM wParam,
  363. LPARAM lParam
  364. )
  365. {
  366. HWND hwndParentDlg = GetParent(hDlg);
  367. PHARDWAREWIZ HardwareWiz = (PHARDWAREWIZ)GetWindowLongPtr(hDlg, DWLP_USER);
  368. UNREFERENCED_PARAMETER(wParam);
  369. switch (wMsg) {
  370. case WM_INITDIALOG: {
  371. LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
  372. HardwareWiz = (PHARDWAREWIZ)lppsp->lParam;
  373. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)HardwareWiz);
  374. break;
  375. }
  376. case WM_DESTROY:
  377. break;
  378. case WM_NOTIFY:
  379. switch (((NMHDR FAR *)lParam)->code) {
  380. case PSN_SETACTIVE: {
  381. int PrevPage, BackUpPage;
  382. PrevPage = HardwareWiz->PrevPage;
  383. HardwareWiz->PrevPage = IDD_ADDDEVICE_SELECTDEVICE;
  384. BackUpPage = HardwareWiz->EnterInto == IDD_ADDDEVICE_SELECTDEVICE
  385. ? HardwareWiz->EnterFrom : IDD_ADDDEVICE_SELECTCLASS;
  386. //
  387. // If we are coming from select class, driver update or Install NewDevice
  388. // then we are going forward.
  389. //
  390. if (!HardwareWiz->ClassGuidSelected || PrevPage == IDD_WIZARDEXT_PRESELECT) {
  391. //
  392. // going backwards, cleanup and backup
  393. //
  394. SetupDiSetSelectedDriver(HardwareWiz->hDeviceInfo,
  395. &HardwareWiz->DeviceInfoData,
  396. NULL
  397. );
  398. SetupDiDestroyDriverInfoList(HardwareWiz->hDeviceInfo,
  399. &HardwareWiz->DeviceInfoData,
  400. SPDIT_COMPATDRIVER
  401. );
  402. SetupDiDestroyDriverInfoList(HardwareWiz->hDeviceInfo,
  403. &HardwareWiz->DeviceInfoData,
  404. SPDIT_CLASSDRIVER
  405. );
  406. //
  407. // Cleanup the WizExtPreSelect Page
  408. //
  409. if (HardwareWiz->WizExtPreSelect.hPropSheet) {
  410. PropSheet_RemovePage(GetParent(hDlg),
  411. (WPARAM)-1,
  412. HardwareWiz->WizExtPreSelect.hPropSheet
  413. );
  414. }
  415. SetDlgMsgResult(hDlg, wMsg, BackUpPage);
  416. break;
  417. }
  418. // Set the Cursor to an Hourglass
  419. SetCursor(LoadCursor(NULL, IDC_WAIT));
  420. HardwareWiz->WizExtPreSelect.hPropSheet = CreateWizExtPage(IDD_WIZARDEXT_PRESELECT,
  421. WizExtPreSelectDlgProc,
  422. HardwareWiz
  423. );
  424. if (HardwareWiz->WizExtPreSelect.hPropSheet) {
  425. PropSheet_AddPage(hwndParentDlg, HardwareWiz->WizExtPreSelect.hPropSheet);
  426. SetDlgMsgResult(hDlg, wMsg, IDD_WIZARDEXT_PRESELECT);
  427. }
  428. else {
  429. SetDlgMsgResult(hDlg, wMsg, BackUpPage);
  430. }
  431. break;
  432. }
  433. }
  434. break;
  435. default:
  436. return(FALSE);
  437. }
  438. return(TRUE);
  439. }
  440. INT_PTR CALLBACK
  441. WizExtPreSelectDlgProc(
  442. HWND hDlg,
  443. UINT wMsg,
  444. WPARAM wParam,
  445. LPARAM lParam
  446. )
  447. {
  448. HWND hwndParentDlg = GetParent(hDlg);
  449. PHARDWAREWIZ HardwareWiz = (PHARDWAREWIZ)GetWindowLongPtr(hDlg, DWLP_USER);
  450. int PrevPageId;
  451. UNREFERENCED_PARAMETER(wParam);
  452. switch (wMsg) {
  453. case WM_INITDIALOG: {
  454. LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
  455. HardwareWiz = (PHARDWAREWIZ)lppsp->lParam;
  456. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)HardwareWiz);
  457. break;
  458. }
  459. case WM_DESTROY:
  460. break;
  461. case WM_NOTIFY:
  462. switch (((NMHDR FAR *)lParam)->code) {
  463. case PSN_SETACTIVE:
  464. PrevPageId = HardwareWiz->PrevPage;
  465. HardwareWiz->PrevPage = IDD_WIZARDEXT_PRESELECT;
  466. if (PrevPageId == IDD_ADDDEVICE_SELECTDEVICE) {
  467. //
  468. // Moving forward on first page
  469. //
  470. //
  471. // Set the Cursor to an Hourglass
  472. //
  473. SetCursor(LoadCursor(NULL, IDC_WAIT));
  474. //
  475. // Add ClassWizard Extension pages
  476. //
  477. AddClassWizExtPages(hwndParentDlg,
  478. HardwareWiz,
  479. &HardwareWiz->WizExtPreSelect.DeviceWizardData,
  480. DIF_NEWDEVICEWIZARD_PRESELECT
  481. );
  482. //
  483. // Add the end page, which is first of the select page set
  484. //
  485. HardwareWiz->WizExtSelect.hPropSheet = CreateWizExtPage(IDD_WIZARDEXT_SELECT,
  486. WizExtSelectDlgProc,
  487. HardwareWiz
  488. );
  489. if (HardwareWiz->WizExtSelect.hPropSheet) {
  490. PropSheet_AddPage(hwndParentDlg, HardwareWiz->WizExtSelect.hPropSheet);
  491. }
  492. PropSheet_PressButton(hwndParentDlg, PSBTN_NEXT);
  493. } else {
  494. //
  495. // Moving backwards on first page
  496. //
  497. //
  498. // Clean up proppages added.
  499. //
  500. if (HardwareWiz->WizExtSelect.hPropSheet) {
  501. PropSheet_RemovePage(hwndParentDlg,
  502. (WPARAM)-1,
  503. HardwareWiz->WizExtSelect.hPropSheet
  504. );
  505. HardwareWiz->WizExtSelect.hPropSheet = NULL;
  506. }
  507. RemoveClassWizExtPages(hwndParentDlg,
  508. &HardwareWiz->WizExtPreSelect.DeviceWizardData
  509. );
  510. //
  511. // Jump back
  512. //
  513. SetDlgMsgResult(hDlg, wMsg, IDD_ADDDEVICE_SELECTDEVICE);
  514. }
  515. break;
  516. case PSN_WIZNEXT:
  517. SetDlgMsgResult(hDlg, wMsg, 0);
  518. break;
  519. }
  520. break;
  521. default:
  522. return(FALSE);
  523. }
  524. return(TRUE);
  525. }
  526. INT_PTR CALLBACK
  527. WizExtSelectDlgProc(
  528. HWND hDlg,
  529. UINT wMsg,
  530. WPARAM wParam,
  531. LPARAM lParam
  532. )
  533. {
  534. HWND hwndParentDlg = GetParent(hDlg);
  535. PHARDWAREWIZ HardwareWiz = (PHARDWAREWIZ)GetWindowLongPtr(hDlg, DWLP_USER);
  536. int PrevPageId;
  537. PSP_INSTALLWIZARD_DATA InstallWizard;
  538. UNREFERENCED_PARAMETER(wParam);
  539. switch (wMsg) {
  540. case WM_INITDIALOG: {
  541. LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
  542. HardwareWiz = (PHARDWAREWIZ)lppsp->lParam;
  543. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)HardwareWiz);
  544. break;
  545. }
  546. case WM_DESTROY:
  547. DestroyDynamicWizard(hwndParentDlg, HardwareWiz, TRUE);
  548. break;
  549. case WM_NOTIFY:
  550. switch (((NMHDR FAR *)lParam)->code) {
  551. case PSN_SETACTIVE:
  552. PrevPageId = HardwareWiz->PrevPage;
  553. HardwareWiz->PrevPage = IDD_WIZARDEXT_SELECT;
  554. if (PrevPageId == IDD_WIZARDEXT_PRESELECT) {
  555. SP_DEVINSTALL_PARAMS DeviceInstallParams;
  556. //
  557. // Moving forward on first page
  558. //
  559. //
  560. // Prepare to call the class installer, for class install wizard pages.
  561. // and Add in setup's SelectDevice wizard page.
  562. //
  563. InstallWizard = &HardwareWiz->InstallDynaWiz;
  564. memset(InstallWizard, 0, sizeof(SP_INSTALLWIZARD_DATA));
  565. InstallWizard->ClassInstallHeader.InstallFunction = DIF_INSTALLWIZARD;
  566. InstallWizard->ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  567. InstallWizard->hwndWizardDlg = GetParent(hDlg);
  568. if (!SetupDiSetClassInstallParams(HardwareWiz->hDeviceInfo,
  569. &HardwareWiz->DeviceInfoData,
  570. &InstallWizard->ClassInstallHeader,
  571. sizeof(SP_INSTALLWIZARD_DATA)
  572. ))
  573. {
  574. SetDlgMsgResult(hDlg, wMsg, IDD_WIZARDEXT_PRESELECT);
  575. break;
  576. }
  577. //
  578. // Get current DeviceInstall parameters, and then set the fields
  579. // we wanted changed from default
  580. //
  581. DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  582. if (!SetupDiGetDeviceInstallParams(HardwareWiz->hDeviceInfo,
  583. &HardwareWiz->DeviceInfoData,
  584. &DeviceInstallParams
  585. ))
  586. {
  587. SetDlgMsgResult(hDlg, wMsg, IDD_WIZARDEXT_PRESELECT);
  588. break;
  589. }
  590. DeviceInstallParams.Flags |= DI_SHOWCLASS | DI_SHOWOEM | DI_CLASSINSTALLPARAMS;
  591. if (IsEqualGUID(HardwareWiz->ClassGuidSelected, &GUID_DEVCLASS_UNKNOWN)) {
  592. DeviceInstallParams.FlagsEx &= ~DI_FLAGSEX_FILTERCLASSES;
  593. } else {
  594. DeviceInstallParams.FlagsEx |= DI_FLAGSEX_FILTERCLASSES;
  595. }
  596. DeviceInstallParams.hwndParent = hwndParentDlg;
  597. if (!SetupDiSetDeviceInstallParams(HardwareWiz->hDeviceInfo,
  598. &HardwareWiz->DeviceInfoData,
  599. &DeviceInstallParams
  600. ))
  601. {
  602. SetDlgMsgResult(hDlg, wMsg, IDD_WIZARDEXT_PRESELECT);
  603. break;
  604. }
  605. //
  606. // Call the class installer for installwizard
  607. // If no class install wizard pages default to run the standard
  608. // setup wizard select device page.
  609. //
  610. if (SetupDiCallClassInstaller(DIF_INSTALLWIZARD,
  611. HardwareWiz->hDeviceInfo,
  612. &HardwareWiz->DeviceInfoData
  613. )
  614. &&
  615. SetupDiGetClassInstallParams(HardwareWiz->hDeviceInfo,
  616. &HardwareWiz->DeviceInfoData,
  617. &InstallWizard->ClassInstallHeader,
  618. sizeof(SP_INSTALLWIZARD_DATA),
  619. NULL
  620. )
  621. &&
  622. InstallWizard->NumDynamicPages)
  623. {
  624. DWORD Pages;
  625. InstallWizard->DynamicPageFlags |= DYNAWIZ_FLAG_PAGESADDED;
  626. for (Pages = 0; Pages < InstallWizard->NumDynamicPages; ++Pages ) {
  627. PropSheet_AddPage(hwndParentDlg, InstallWizard->DynamicPages[Pages]);
  628. }
  629. HardwareWiz->SelectDevicePage = SetupDiGetWizardPage(HardwareWiz->hDeviceInfo,
  630. &HardwareWiz->DeviceInfoData,
  631. InstallWizard,
  632. SPWPT_SELECTDEVICE,
  633. SPWP_USE_DEVINFO_DATA
  634. );
  635. PropSheet_AddPage(hwndParentDlg, HardwareWiz->SelectDevicePage);
  636. } else {
  637. InstallWizard->DynamicPageFlags = 0;
  638. HardwareWiz->SelectDevicePage = NULL;
  639. if (!AddClassWizExtPages(hwndParentDlg,
  640. HardwareWiz,
  641. &HardwareWiz->WizExtSelect.DeviceWizardData,
  642. DIF_NEWDEVICEWIZARD_SELECT
  643. ))
  644. {
  645. HardwareWiz->SelectDevicePage = SetupDiGetWizardPage(HardwareWiz->hDeviceInfo,
  646. &HardwareWiz->DeviceInfoData,
  647. InstallWizard,
  648. SPWPT_SELECTDEVICE,
  649. SPWP_USE_DEVINFO_DATA
  650. );
  651. PropSheet_AddPage(hwndParentDlg, HardwareWiz->SelectDevicePage);
  652. }
  653. }
  654. //
  655. // Clear the class install parameters.
  656. //
  657. SetupDiSetClassInstallParams(HardwareWiz->hDeviceInfo,
  658. &HardwareWiz->DeviceInfoData,
  659. NULL,
  660. 0
  661. );
  662. //
  663. // Add the end page, which is the preanalyze page.
  664. //
  665. HardwareWiz->WizExtPreAnalyze.hPropSheet = CreateWizExtPage(IDD_WIZARDEXT_PREANALYZE,
  666. WizExtPreAnalyzeDlgProc,
  667. HardwareWiz
  668. );
  669. PropSheet_AddPage(hwndParentDlg, HardwareWiz->WizExtPreAnalyze.hPropSheet);
  670. PropSheet_PressButton(hwndParentDlg, PSBTN_NEXT);
  671. } else {
  672. //
  673. // Moving backwards on first page
  674. //
  675. //
  676. // Clean up proppages added.
  677. //
  678. DestroyDynamicWizard(hwndParentDlg, HardwareWiz, FALSE);
  679. if (HardwareWiz->SelectDevicePage) {
  680. PropSheet_RemovePage(hwndParentDlg,
  681. (WPARAM)-1,
  682. HardwareWiz->SelectDevicePage
  683. );
  684. HardwareWiz->SelectDevicePage = NULL;
  685. }
  686. if (HardwareWiz->WizExtPreAnalyze.hPropSheet) {
  687. PropSheet_RemovePage(hwndParentDlg,
  688. (WPARAM)-1,
  689. HardwareWiz->WizExtPreAnalyze.hPropSheet
  690. );
  691. HardwareWiz->WizExtPreAnalyze.hPropSheet = NULL;
  692. }
  693. RemoveClassWizExtPages(hwndParentDlg,
  694. &HardwareWiz->WizExtSelect.DeviceWizardData
  695. );
  696. //
  697. // Jump back
  698. //
  699. SetDlgMsgResult(hDlg, wMsg, IDD_WIZARDEXT_PRESELECT);
  700. }
  701. break;
  702. case PSN_WIZNEXT:
  703. SetDlgMsgResult(hDlg, wMsg, 0);
  704. break;
  705. }
  706. break;
  707. default:
  708. return(FALSE);
  709. }
  710. return(TRUE);
  711. }