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.

972 lines
32 KiB

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