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.

1038 lines
27 KiB

  1. /*
  2. File wizard.c
  3. Implementation of the incoming connections wizard.
  4. Paul Mayfield, 10/30/97
  5. */
  6. #include "rassrv.h"
  7. #include <tapi.h>
  8. // Help maps
  9. static const DWORD phmWizardDccdev[] =
  10. {
  11. CID_Wizard_Dccdev_LB_Devices, IDH_Wizard_Dccdev_LB_Devices,
  12. 0, 0
  13. };
  14. static const DWORD phmWizardVpn[] =
  15. {
  16. 0, 0
  17. };
  18. #define RASSRV_WIZTITLE_SIZE 256
  19. #define RASSRV_WIZSUBTITLE_SIZE 256
  20. // This structure let's us remember information needed
  21. // to keep our device data page in sync
  22. typedef struct _DCCDEV_DATA
  23. {
  24. HANDLE hDevice;
  25. BOOL bEnabled;
  26. } DCCDEV_DATA;
  27. //
  28. // This dialog proc implements the vpn tab on the incoming connections
  29. // wizard.
  30. //
  31. INT_PTR
  32. CALLBACK
  33. VpnWizDialogProc(
  34. HWND hwndDlg,
  35. UINT uMsg,
  36. WPARAM wParam,
  37. LPARAM lParam);
  38. //
  39. // Dialog procedure that handles the host dcc wizard device page
  40. //
  41. INT_PTR
  42. CALLBACK
  43. DccdevWizDialogProc(
  44. HWND hwndDlg,
  45. UINT uMsg,
  46. WPARAM wParam,
  47. LPARAM lParam);
  48. //
  49. // This dialog procedure responds to messages sent to the
  50. // switch to mmc wizard tab.
  51. //
  52. INT_PTR
  53. CALLBACK
  54. SwitchMmcWizDialogProc (
  55. HWND hwndDlg,
  56. UINT uMsg,
  57. WPARAM wParam,
  58. LPARAM lParam);
  59. //
  60. // Fills in the property sheet structure with the information required to
  61. // display the device tab in the incoming connections wizard.
  62. //
  63. DWORD
  64. DeviceWizGetPropertyPage(
  65. IN LPPROPSHEETPAGE ppage,
  66. IN LPARAM lpUserData)
  67. {
  68. LPCTSTR pszHeader, pszSubHeader;
  69. // Initialize
  70. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  71. // Load the string resources
  72. pszHeader = PszLoadString(
  73. Globals.hInstDll,
  74. SID_WIZDEVICETITLE);
  75. pszSubHeader = PszLoadString(
  76. Globals.hInstDll,
  77. SID_WIZDEVICESUBTITLE);
  78. // The General Properties dialog procedure also implements the device
  79. // tab in the incoming connections wizard
  80. ppage->pfnDlgProc = GenTabDialogProc;
  81. // Fill in the values
  82. ppage->dwSize = sizeof(PROPSHEETPAGE);
  83. ppage->hInstance = Globals.hInstDll;
  84. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_GenTab);
  85. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  86. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  87. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  88. ppage->lParam = lpUserData;
  89. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  90. PSP_USEHEADERTITLE |
  91. PSP_USECALLBACK;
  92. return NO_ERROR;
  93. }
  94. //
  95. // Fills in the property sheet structure with the information required
  96. // to display the vpn tab in the incoming connections wizard.
  97. //
  98. DWORD
  99. VpnWizGetPropertyPage(
  100. IN LPPROPSHEETPAGE ppage,
  101. IN LPARAM lpUserData)
  102. {
  103. LPCTSTR pszHeader, pszSubHeader;
  104. // Initialize
  105. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  106. // Load the string resources
  107. pszHeader = PszLoadString(
  108. Globals.hInstDll,
  109. SID_WIZVPNTITLE);
  110. pszSubHeader = PszLoadString(
  111. Globals.hInstDll,
  112. SID_WIZVPNSUBTITLE);
  113. // I could have used the general tab dialog procedure to implement the
  114. // vpn tab. The only problem is that the general tab has a single
  115. // check to enable vpn while the vpn tab in the wizard has a yes/no
  116. // radio check group. For this reason, I made the vpn tab its very
  117. // own dialog proc.
  118. ppage->pfnDlgProc = VpnWizDialogProc;
  119. // Fill in the values
  120. ppage->dwSize = sizeof(PROPSHEETPAGE);
  121. ppage->hInstance = Globals.hInstDll;
  122. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_Vpn);
  123. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  124. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  125. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  126. ppage->lParam = lpUserData;
  127. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  128. PSP_USEHEADERTITLE |
  129. PSP_USECALLBACK;
  130. return NO_ERROR;
  131. }
  132. //
  133. // Function fills in the given lpPage structure with the information needed
  134. // to run the user tab in the incoming connections wizard.
  135. //
  136. DWORD
  137. UserWizGetPropertyPage(
  138. IN LPPROPSHEETPAGE ppage,
  139. IN LPARAM lpUserData)
  140. {
  141. LPCTSTR pszHeader, pszSubHeader;
  142. // Initialize
  143. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  144. // Load the string resources
  145. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZUSERTITLE);
  146. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZUSERSUBTITLE);
  147. // The User Properties dialog procedure also implements the user tab
  148. // in the incoming connections wizard
  149. ppage->pfnDlgProc = UserTabDialogProc;
  150. // Fill in the values
  151. ppage->dwSize = sizeof(PROPSHEETPAGE);
  152. ppage->hInstance = Globals.hInstDll;
  153. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_UserTab);
  154. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  155. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  156. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  157. ppage->lParam = lpUserData;
  158. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  159. PSP_USEHEADERTITLE |
  160. PSP_USECALLBACK;
  161. return NO_ERROR;
  162. }
  163. //
  164. // Fills a LPPROPSHEETPAGE structure with the information
  165. // needed to display the protocol tab in the incoming connections wizard.
  166. //
  167. DWORD
  168. ProtWizGetPropertyPage(
  169. IN LPPROPSHEETPAGE ppage,
  170. IN LPARAM lpUserData)
  171. {
  172. LPCTSTR pszHeader, pszSubHeader;
  173. // Initialize
  174. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  175. // Load the string resources
  176. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZPROTTITLE);
  177. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZPROTSUBTITLE);
  178. // The Advanced Properties dialog procedure also implements the net tab
  179. // in the incoming connections wizard
  180. ppage->pfnDlgProc = NetTabDialogProc;
  181. // Fill in the values
  182. ppage->dwSize = sizeof(PROPSHEETPAGE);
  183. ppage->hInstance = Globals.hInstDll;
  184. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_NetTab);
  185. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  186. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  187. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  188. ppage->lParam = lpUserData;
  189. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  190. PSP_USEHEADERTITLE |
  191. PSP_USECALLBACK;
  192. return NO_ERROR;
  193. }
  194. //
  195. // Function fills in the given LPPROPSHEETPAGE structure with the info
  196. // needed to run the dcc device tab in the incoming connections wizard.
  197. //
  198. DWORD
  199. DccdevWizGetPropertyPage(
  200. IN LPPROPSHEETPAGE ppage,
  201. IN LPARAM lpUserData)
  202. {
  203. LPCTSTR pszHeader, pszSubHeader;
  204. // Initialize
  205. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  206. // Load the string resources
  207. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZDCCDEVTITLE);
  208. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZDCCDEVSUBTITLE);
  209. // The Advanced Properties dialog procedure also implements the protocol
  210. // tab in the incoming connections wizard
  211. ppage->pfnDlgProc = DccdevWizDialogProc;
  212. // Fill in the values
  213. ppage->dwSize = sizeof(PROPSHEETPAGE);
  214. ppage->hInstance = Globals.hInstDll;
  215. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_Dccdev);
  216. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  217. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  218. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  219. ppage->lParam = lpUserData;
  220. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  221. PSP_USEHEADERTITLE |
  222. PSP_USECALLBACK;
  223. return NO_ERROR;
  224. }
  225. //
  226. // Function fills in the given LPPROPSHEETPAGE structure with the
  227. // information needed to run the dummy wizard page that switches to mmc.
  228. //
  229. DWORD
  230. SwitchMmcWizGetProptertyPage (
  231. IN LPPROPSHEETPAGE ppage,
  232. IN LPARAM lpUserData)
  233. {
  234. // Initialize
  235. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  236. // The Advanced Properties dialog procedure also implements
  237. // the protocol tab in the incoming connections wizard
  238. ppage->pfnDlgProc = SwitchMmcWizDialogProc;
  239. // Fill in the values
  240. ppage->dwSize = sizeof(PROPSHEETPAGE);
  241. ppage->hInstance = Globals.hInstDll;
  242. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_SwitchMmc);
  243. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  244. ppage->lParam = lpUserData;
  245. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  246. PSP_USEHEADERTITLE |
  247. PSP_USECALLBACK;
  248. return NO_ERROR;
  249. }
  250. //
  251. // Initializes the vpn wizard tab.
  252. //
  253. DWORD
  254. VpnWizInitializeDialog(
  255. IN HWND hwndDlg,
  256. IN WPARAM wParam)
  257. {
  258. DWORD dwErr;
  259. BOOL bFlag;
  260. HANDLE hDevDatabase = NULL;
  261. // Get handles to the databases we're interested in
  262. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  263. // Initialize the vpn check
  264. dwErr = devGetVpnEnable(hDevDatabase, &bFlag);
  265. if (dwErr != NO_ERROR)
  266. {
  267. ErrDisplayError(
  268. hwndDlg,
  269. ERR_DEVICE_DATABASE_CORRUPT,
  270. ERR_GENERALTAB_CATAGORY,
  271. 0,
  272. Globals.dwErrorData);
  273. return dwErr;
  274. }
  275. SendMessage(GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_Yes),
  276. BM_SETCHECK,
  277. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  278. 0);
  279. SendMessage(GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_No),
  280. BM_SETCHECK,
  281. (!bFlag) ? BST_CHECKED : BST_UNCHECKED,
  282. 0);
  283. return NO_ERROR;
  284. }
  285. //
  286. // Handles cancel button being pressed for the vpn wizard page
  287. //
  288. DWORD
  289. VpnWizCancelEdit(
  290. IN HWND hwndDlg,
  291. IN NMHDR* pNotifyData)
  292. {
  293. HANDLE hDevDatabase = NULL;
  294. DWORD dwErr;
  295. DbgOutputTrace("Rolling back vpn wizard tab.");
  296. // Cancel flush of database
  297. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  298. dwErr = devRollbackDatabase(hDevDatabase);
  299. if (dwErr != NO_ERROR)
  300. {
  301. ErrDisplayError(
  302. hwndDlg,
  303. ERR_GENERAL_CANT_ROLLBACK_CHANGES,
  304. ERR_GENERALTAB_CATAGORY,
  305. 0,
  306. Globals.dwErrorData);
  307. }
  308. return NO_ERROR;
  309. }
  310. //
  311. // Handles having the vpn wizard come active
  312. //
  313. DWORD
  314. VpnWizSetActive (
  315. IN HWND hwndDlg,
  316. IN WPARAM wParam,
  317. IN LPARAM lParam)
  318. {
  319. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  320. return NO_ERROR;
  321. }
  322. //
  323. // Handles vpn loose activation messages
  324. //
  325. DWORD
  326. VpnWizKillActive (
  327. IN HWND hwndDlg,
  328. IN WPARAM wParam,
  329. IN LPARAM lParam)
  330. {
  331. HANDLE hDevDatabase = NULL;
  332. BOOL bEnable;
  333. //For Whistler bug#123769
  334. //In order to let the SetPortMapping commit
  335. //when creating a new IC connection, we set
  336. //the fVpnEnabledOrig to be different from
  337. // the fVpnEnable
  338. //
  339. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  340. bEnable = IsDlgButtonChecked( hwndDlg, CID_Wizard_Vpn_RB_Yes );
  341. devSetVpnOrigEnable(hDevDatabase, !bEnable);
  342. return NO_ERROR;
  343. }
  344. //
  345. // Processes command messages for the vpn wizard page
  346. //
  347. DWORD
  348. VpnWizCommand(
  349. IN HWND hwndDlg,
  350. IN WPARAM wParam,
  351. IN LPARAM lParam)
  352. {
  353. HANDLE hDevDatabase = NULL;
  354. BOOL bEnable;
  355. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  356. if (wParam == CID_Wizard_Vpn_RB_Yes || wParam == CID_Wizard_Vpn_RB_No)
  357. {
  358. bEnable = (BOOL) SendMessage(
  359. GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_Yes),
  360. BM_GETCHECK,
  361. 0,
  362. 0);
  363. devSetVpnEnable(hDevDatabase, bEnable);
  364. }
  365. return NO_ERROR;
  366. }
  367. //
  368. // This dialog procedure responds to messages sent to the
  369. // vpn wizard tab.
  370. //
  371. INT_PTR CALLBACK
  372. VpnWizDialogProc(
  373. IN HWND hwndDlg,
  374. IN UINT uMsg,
  375. IN WPARAM wParam,
  376. IN LPARAM lParam)
  377. {
  378. // Filter the customized ras server ui page messages. By filtering
  379. // messages through here, we are able to call RasSrvGetDatabaseHandle
  380. // below
  381. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  382. return TRUE;
  383. // Process other messages as normal
  384. switch (uMsg)
  385. {
  386. case WM_INITDIALOG:
  387. return FALSE;
  388. break;
  389. case WM_NOTIFY:
  390. switch (((NMHDR*)lParam)->code)
  391. {
  392. case PSN_RESET:
  393. VpnWizCancelEdit(hwndDlg, (NMHDR*)lParam);
  394. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  395. break;
  396. case PSN_SETACTIVE:
  397. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  398. {
  399. VpnWizInitializeDialog(hwndDlg, wParam);
  400. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 1);
  401. }
  402. VpnWizSetActive (hwndDlg, wParam, lParam);
  403. break;
  404. case PSN_KILLACTIVE:
  405. VpnWizKillActive (hwndDlg, wParam, lParam);
  406. break;
  407. }
  408. case WM_COMMAND:
  409. VpnWizCommand(hwndDlg, wParam, lParam);
  410. break;
  411. }
  412. return FALSE;
  413. }
  414. // Fill the device combo box
  415. DWORD
  416. DccdevFillDeviceList(
  417. IN HWND hwndDlg,
  418. IN HANDLE hDevDatabase,
  419. IN HANDLE hDevSelect)
  420. {
  421. HWND hwndCb = GetDlgItem(hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  422. DWORD dwCount, dwIndex, dwErr, i, j=0, dwSelect = 0;
  423. HANDLE hDevice;
  424. PWCHAR pszName = NULL;
  425. // Delete anything that was in the combo box
  426. SendMessage(hwndCb, CB_RESETCONTENT, 0, 0);
  427. // Get the count of devices
  428. if ((dwErr = devGetDeviceCount(hDevDatabase, &dwCount)) != NO_ERROR)
  429. {
  430. return dwErr;
  431. }
  432. // Add them to the device combo box
  433. for (i = 0; i < dwCount; i++)
  434. {
  435. // If the device wasn't filtered out, add it to the combo
  436. // box and remember its handle
  437. dwErr = devGetDeviceHandle(hDevDatabase, i, &hDevice);
  438. if (dwErr == NO_ERROR)
  439. {
  440. devGetDeviceName (hDevice, &pszName);
  441. dwIndex = (DWORD) SendMessage (
  442. hwndCb,
  443. CB_ADDSTRING,
  444. 0,
  445. (LPARAM)pszName);
  446. SendMessage (
  447. hwndCb,
  448. CB_SETITEMDATA,
  449. dwIndex,
  450. (LPARAM)hDevice);
  451. // If this is the device to select, remember that fact
  452. if (hDevice == hDevSelect)
  453. {
  454. dwSelect = j;
  455. }
  456. j++;
  457. }
  458. }
  459. ComboBox_SetCurSel(hwndCb, dwSelect);
  460. return NO_ERROR;
  461. }
  462. //
  463. // Initializes the dcc device wizard tab.
  464. //
  465. DWORD
  466. DccdevWizInitializeDialog(
  467. IN HWND hwndDlg,
  468. IN WPARAM wParam)
  469. {
  470. HANDLE hDevDatabase = NULL, hDevice = NULL;
  471. DWORD dwStatus, dwErr, dwCount, i;
  472. BOOL bEnabled;
  473. DCCDEV_DATA * pDcData;
  474. // Whenever the dcc device page is left, the currently selected device
  475. // is remembered and its original enabling is recorded. Then this device
  476. // is set to enabled. Whenever the page is activated, the remembered
  477. // device is restored to its original enabling state if it is still
  478. // enabled.
  479. //
  480. // This whole process is a little confusing, but it ensures that the dcc
  481. // device page will interact correctly when the user goes down the dcc
  482. // path and then the incoming path and back and forth.
  483. //
  484. if ((pDcData = RassrvAlloc (sizeof(DCCDEV_DATA), TRUE)) == NULL)
  485. {
  486. return ERROR_NOT_ENOUGH_MEMORY;
  487. }
  488. // Get handles to the databases we're interested in
  489. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  490. // Add the com ports as devices and filter out all non dcc
  491. // devices from the device database
  492. devFilterDevices(hDevDatabase, INCOMING_TYPE_DIRECT);
  493. devAddComPorts(hDevDatabase);
  494. // Get the count of devices
  495. if ((dwErr = devGetDeviceCount(hDevDatabase, &dwCount)) != NO_ERROR)
  496. {
  497. return dwErr;
  498. }
  499. // Get the handle to the first device if any
  500. for (i = 0; i < dwCount; i++)
  501. {
  502. if (devGetDeviceHandle (hDevDatabase, i, &hDevice) == NO_ERROR)
  503. {
  504. break;
  505. }
  506. }
  507. // Record the device's enabling -- index is 0 (default)
  508. if (hDevice)
  509. {
  510. dwErr = devGetDeviceEnable (hDevice, &(pDcData->bEnabled));
  511. if (dwErr != NO_ERROR)
  512. {
  513. return dwErr;
  514. }
  515. pDcData->hDevice = hDevice;
  516. }
  517. // Record the status bits
  518. SetWindowLongPtr (hwndDlg, GWLP_USERDATA, (LONG_PTR)pDcData);
  519. return NO_ERROR;
  520. }
  521. //
  522. // Cleans up the dcc device wizard
  523. //
  524. DWORD
  525. DccdevWizCleanupDialog(
  526. IN HWND hwndDlg,
  527. IN WPARAM wParam,
  528. IN LPARAM lParam)
  529. {
  530. DCCDEV_DATA * pDcData =
  531. (DCCDEV_DATA *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  532. if (pDcData)
  533. {
  534. RassrvFree (pDcData);
  535. }
  536. return NO_ERROR;
  537. }
  538. //
  539. // Called to do any processing when the dcc wizard device page is
  540. // gaining focus
  541. //
  542. DWORD
  543. DccdevWizSetActive (
  544. IN HWND hwndDlg,
  545. IN WPARAM wParam,
  546. IN LPARAM lParam)
  547. {
  548. HANDLE hDevDatabase = NULL;
  549. BOOL bEnabled;
  550. DCCDEV_DATA * pDcData;
  551. // Whenever the page is activated, the remembered device
  552. // is restored to its original enabling state if it is still enabled.
  553. pDcData = (DCCDEV_DATA*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  554. if (pDcData && pDcData->hDevice)
  555. {
  556. if (devGetDeviceEnable (pDcData->hDevice, &bEnabled) == NO_ERROR)
  557. {
  558. if (bEnabled)
  559. {
  560. devSetDeviceEnable (pDcData->hDevice, pDcData->bEnabled);
  561. }
  562. }
  563. }
  564. // Get handles to the databases we're interested in
  565. RasSrvGetDatabaseHandle (hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  566. // Fill the device combo box
  567. DccdevFillDeviceList (
  568. hwndDlg,
  569. hDevDatabase,
  570. (pDcData) ? pDcData->hDevice : NULL);
  571. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  572. return NO_ERROR;
  573. }
  574. //
  575. // Called to do any processing when the dcc wizard device
  576. // page is loosing focus
  577. //
  578. DWORD
  579. DccdevWizKillActive (
  580. IN HWND hwndDlg,
  581. IN WPARAM wParam,
  582. IN LPARAM lParam)
  583. {
  584. HANDLE hDevDatabase = NULL, hDevice = NULL;
  585. DCCDEV_DATA * pDcData;
  586. INT iCurSel;
  587. HWND hwndCb = GetDlgItem (hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  588. DWORD dwErr;
  589. // Whenever the dcc device page is left, the currently selected
  590. // device is remembered and its original enabling is recorded.
  591. // Then this device is set to enabled.
  592. pDcData = (DCCDEV_DATA*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  593. if (pDcData)
  594. {
  595. iCurSel = ComboBox_GetCurSel(hwndCb);
  596. if (iCurSel != -1)
  597. {
  598. hDevice = (HANDLE) ComboBox_GetItemData(hwndCb, iCurSel);
  599. dwErr = devGetDeviceEnable (hDevice, &(pDcData->bEnabled));
  600. if (dwErr == NO_ERROR)
  601. {
  602. pDcData->hDevice = hDevice;
  603. devSetDeviceEnable (hDevice, TRUE);
  604. }
  605. }
  606. else
  607. {
  608. pDcData->hDevice = NULL;
  609. }
  610. }
  611. // Get handles to the databases we're interested in
  612. RasSrvGetDatabaseHandle(
  613. hwndDlg,
  614. ID_DEVICE_DATABASE,
  615. &hDevDatabase);
  616. // Undo the filter so that other pages aren't affected
  617. //devFilterDevices(
  618. // hDevDatabase,
  619. // 0xffffffff);
  620. return NO_ERROR;
  621. }
  622. //
  623. // Called to cancel the edit operation on the dcc host
  624. // device wizard tab.
  625. //
  626. DWORD
  627. DccdevWizCancelEdit(
  628. IN HWND hwndDlg,
  629. IN NMHDR* pNotifyData)
  630. {
  631. HANDLE hDevDatabase = NULL;
  632. DWORD dwErr;
  633. DbgOutputTrace("Rolling back dcc device wizard tab.");
  634. // Cancel the commit on the device database
  635. RasSrvGetDatabaseHandle(
  636. hwndDlg,
  637. ID_DEVICE_DATABASE,
  638. &hDevDatabase);
  639. dwErr = devRollbackDatabase(hDevDatabase);
  640. if (dwErr != NO_ERROR)
  641. {
  642. ErrDisplayError(
  643. hwndDlg,
  644. ERR_GENERAL_CANT_ROLLBACK_CHANGES,
  645. ERR_GENERALTAB_CATAGORY,
  646. 0,
  647. Globals.dwErrorData);
  648. }
  649. return NO_ERROR;
  650. }
  651. //
  652. // Raises properties for a component
  653. //
  654. DWORD
  655. DccdevWizRaiseProperties (
  656. IN HWND hwndDlg,
  657. IN HWND hwndLb,
  658. IN INT iItem)
  659. {
  660. HANDLE hDevice;
  661. DWORD dwErr = NO_ERROR, dwId;
  662. MSGARGS MsgArgs;
  663. BOOL bIsComPort = FALSE;
  664. // Get a handle to the device
  665. hDevice = (HANDLE) ComboBox_GetItemData(hwndLb, iItem);
  666. if (hDevice == NULL)
  667. {
  668. return ERROR_CAN_NOT_COMPLETE;
  669. }
  670. // Find out if the device is a com port which has not yet had a
  671. // null modem installed.
  672. //
  673. dwErr = devDeviceIsComPort(hDevice, &bIsComPort);
  674. if (dwErr != NO_ERROR)
  675. {
  676. return ERROR_CAN_NOT_COMPLETE;
  677. }
  678. // If so, popup info to the user explaining
  679. // the situation.
  680. //
  681. if (bIsComPort)
  682. {
  683. ZeroMemory(&MsgArgs, sizeof(MsgArgs));
  684. MsgArgs.dwFlags = MB_OK | MB_ICONINFORMATION;
  685. MsgDlgUtil(
  686. hwndDlg,
  687. SID_COM_PORT_NOT_ENABLED,
  688. &MsgArgs,
  689. Globals.hInstDll,
  690. SID_DEFAULT_MSG_TITLE);
  691. return NO_ERROR;
  692. }
  693. // Get the tapi id of the device
  694. if (devGetDeviceId(hDevice, &dwId) != NO_ERROR)
  695. {
  696. return ERROR_CAN_NOT_COMPLETE;
  697. }
  698. // Launch the device properties dialog
  699. dwErr = lineConfigDialogW(dwId, hwndDlg, NULL);
  700. if (dwErr == LINEERR_OPERATIONUNAVAIL)
  701. {
  702. ErrDisplayError(
  703. hwndDlg,
  704. ERR_DEVICE_HAS_NO_CONFIG,
  705. ERR_GENERALTAB_CATAGORY,
  706. 0,
  707. Globals.dwErrorData);
  708. dwErr = NO_ERROR;
  709. }
  710. return dwErr;
  711. }
  712. //
  713. // Called when "iItem" is being selected to enable or disable the
  714. // properties button.
  715. //
  716. DWORD
  717. DccdevWizEnableDisableProperties(
  718. IN HWND hwndDlg,
  719. IN HWND hwndLb,
  720. IN INT iItem)
  721. {
  722. return NO_ERROR;
  723. }
  724. //
  725. // Called to cancel the edit operation on the dcc host
  726. // device wizard tab.
  727. //
  728. DWORD
  729. DccdevWizCommand(
  730. HWND hwndDlg,
  731. WPARAM wParam,
  732. LPARAM lParam)
  733. {
  734. switch (LOWORD(wParam))
  735. {
  736. case CID_Dccdev_PB_Properties:
  737. {
  738. HWND hwndLb;
  739. hwndLb = GetDlgItem(hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  740. DccdevWizRaiseProperties(
  741. hwndDlg,
  742. hwndLb,
  743. ComboBox_GetCurSel(hwndLb));
  744. }
  745. break;
  746. case CID_Wizard_Dccdev_LB_Devices:
  747. {
  748. if (HIWORD(wParam) == CBN_SELCHANGE)
  749. {
  750. DccdevWizEnableDisableProperties(
  751. hwndDlg,
  752. (HWND)lParam,
  753. ComboBox_GetCurSel((HWND)lParam));
  754. }
  755. }
  756. break;
  757. }
  758. return NO_ERROR;
  759. }
  760. INT_PTR
  761. CALLBACK
  762. DccdevWizDialogProc(
  763. IN HWND hwndDlg,
  764. IN UINT uMsg,
  765. IN WPARAM wParam,
  766. IN LPARAM lParam)
  767. {
  768. // Filter the customized ras server ui page
  769. // messages. By filtering messages through
  770. // here, we are able to call RasSrvGetDatabaseHandle
  771. // below
  772. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  773. return TRUE;
  774. // Process other messages as normal
  775. switch (uMsg)
  776. {
  777. case WM_INITDIALOG:
  778. return FALSE;
  779. case WM_NOTIFY:
  780. switch (((NMHDR*)lParam)->code)
  781. {
  782. case PSN_RESET:
  783. DccdevWizCancelEdit(hwndDlg, (NMHDR*)lParam);
  784. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  785. break;
  786. case PSN_SETACTIVE:
  787. {
  788. DWORD dwErr;
  789. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  790. {
  791. DccdevWizInitializeDialog(hwndDlg, wParam);
  792. }
  793. dwErr = DccdevWizSetActive (
  794. hwndDlg,
  795. wParam,
  796. lParam);
  797. if (dwErr != NO_ERROR)
  798. {
  799. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  800. }
  801. }
  802. break;
  803. case PSN_KILLACTIVE:
  804. DccdevWizKillActive (hwndDlg, wParam, lParam);
  805. break;
  806. }
  807. break;//for bug 187918
  808. case WM_COMMAND:
  809. DccdevWizCommand(hwndDlg, wParam, lParam);
  810. break;
  811. case WM_DESTROY:
  812. DccdevWizCleanupDialog(hwndDlg, wParam, lParam);
  813. break;
  814. }
  815. return FALSE;
  816. }
  817. //
  818. // Handles the activation of the switch to mmc wizard page.
  819. //
  820. DWORD
  821. SwitchMmcWizSetActive (
  822. IN HWND hwndDlg,
  823. IN WPARAM wParam,
  824. IN LPARAM lParam)
  825. {
  826. PWCHAR pszTitle;
  827. PWCHAR pszMessage;
  828. INT iRet;
  829. // Load the messages to display
  830. pszTitle = (PWCHAR)
  831. PszLoadString(Globals.hInstDll, WRN_WIZARD_NOT_ALLOWED_TITLE);
  832. pszMessage = (PWCHAR)
  833. PszLoadString(Globals.hInstDll, WRN_WIZARD_NOT_ALLOWED_MSG);
  834. iRet = MessageBox (
  835. hwndDlg,
  836. pszMessage,
  837. pszTitle,
  838. MB_YESNO | MB_ICONINFORMATION);
  839. if (iRet == 0)
  840. {
  841. return ERROR_NOT_ENOUGH_MEMORY;
  842. }
  843. // If yes was pressed, switch to mpradmin snapin.
  844. if (iRet == IDYES)
  845. {
  846. RasSrvLeaveServiceRunning (hwndDlg);
  847. PropSheet_PressButton (GetParent (hwndDlg), PSBTN_CANCEL);
  848. RassrvLaunchMMC (RASSRVUI_MPRCONSOLE);
  849. }
  850. // Otherwise, display the welcome page
  851. else if (iRet == IDNO)
  852. {
  853. PropSheet_PressButton (GetParent (hwndDlg), PSBTN_BACK);
  854. }
  855. // No matter what, don't accept activation
  856. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  857. return NO_ERROR;
  858. }
  859. // This dialog procedure responds to messages sent to the
  860. // switch to mmc wizard tab.
  861. INT_PTR
  862. CALLBACK
  863. SwitchMmcWizDialogProc (
  864. HWND hwndDlg,
  865. UINT uMsg,
  866. WPARAM wParam,
  867. LPARAM lParam)
  868. {
  869. // Filter the customized ras server ui page messages. By filtering
  870. // messages through here, we are able to call RasSrvGetDatabaseHandle
  871. // below
  872. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  873. return TRUE;
  874. // Process other messages as normal
  875. switch (uMsg)
  876. {
  877. case WM_NOTIFY:
  878. switch (((NMHDR*)lParam)->code)
  879. {
  880. case PSN_SETACTIVE:
  881. return SwitchMmcWizSetActive (hwndDlg, wParam, lParam);
  882. break;
  883. }
  884. break;
  885. }
  886. return FALSE;
  887. }