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.

1096 lines
28 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A D V P A G E . C P P
  7. //
  8. // Contents: Contains the advanced page for enumerated net class devices
  9. //
  10. // Notes:
  11. //
  12. // Author: nabilr 16 Mar 1997
  13. //
  14. // History: BillBe (24 June 1997) Took over ownership
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "pch.h"
  18. #pragma hdrstop
  19. #include "advpage.h"
  20. #include "pagehelp.h"
  21. #include "ncreg.h"
  22. #include "ncsetup.h"
  23. #include "ncui.h"
  24. const DWORD c_cchMaxRegStrLen = 256;
  25. // name of Answerfile section that contains our Additional (adapter-specific)
  26. // parameters.
  27. static const WCHAR c_szDevMgrHelpFile[] = L"devmgr.hlp";
  28. //+---------------------------------------------------------------------------
  29. //
  30. // Member: CAdvanced::CAdvanced (constructor)
  31. //
  32. // Purpose: Init some variables.
  33. //
  34. // Author: t-nabilr 06 Apr 1997
  35. //
  36. // Notes: The bulk of the setting up occurs in FInit().
  37. //
  38. CAdvanced::CAdvanced()
  39. : m_plbParams(NULL),
  40. m_pedtEdit(NULL),
  41. m_pcbxDrop(NULL),
  42. m_pbmPresent(NULL),
  43. m_pbmNotPresent(NULL),
  44. m_hwndSpin(NULL),
  45. m_hwndPresentText(NULL),
  46. m_nCurSel(0),
  47. m_ctlControlType(CTLTYPE_UNKNOWN),
  48. m_fInitializing(FALSE)
  49. {
  50. }
  51. //+--------------------------------------------------------------------------
  52. //
  53. // Member: CAdvanced::CreatePage
  54. //
  55. // Purpose: Creates the advanced page only if there is information
  56. // to populate the ui
  57. //
  58. // Arguments:
  59. // hdi [in] SetupApi HDEVINFO for device
  60. // pdeid [in] SetupApi PSP_DEVINFO_DATA for device
  61. //
  62. // Returns: HPROPSHEETPAGE
  63. //
  64. // Author: billbe 1 Jul 1997
  65. //
  66. // Notes:
  67. //
  68. HPROPSHEETPAGE
  69. CAdvanced::CreatePage(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid)
  70. {
  71. Assert(IsValidHandle(hdi));
  72. Assert(pdeid);
  73. HPROPSHEETPAGE hpsp = NULL;
  74. if (SUCCEEDED(HrInit(hdi, pdeid)))
  75. {
  76. hpsp = CPropSheetPage::CreatePage(DLG_PARAMS, 0);
  77. }
  78. return hpsp;
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Member: CAdvanced::OnInitDialog
  83. //
  84. // Purpose: Handler for the WM_INITDIALOG windows message. Initializes
  85. // the dialog window.
  86. //
  87. // Author: t-nabilr 06 Apr 1997
  88. //
  89. // Notes:
  90. //
  91. //
  92. LRESULT CAdvanced::OnInitDialog(UINT uMsg, WPARAM wParam,
  93. LPARAM lParam, BOOL& fHandled)
  94. {
  95. const WCHAR * szText;
  96. // We are initializing the property page
  97. m_fInitializing = TRUE;
  98. // Control Pointers
  99. m_plbParams = new CListBox(m_hWnd, IDD_PARAMS_LIST);
  100. if (m_plbParams == NULL)
  101. {
  102. return(0);
  103. }
  104. m_pedtEdit = new CEdit(m_hWnd, IDD_PARAMS_EDIT);
  105. m_pcbxDrop = new CComboBox(m_hWnd, IDD_PARAMS_DROP);
  106. m_pbmPresent = new CButton(m_hWnd, IDD_PARAMS_PRESENT);
  107. m_pbmNotPresent = new CButton(m_hWnd, IDD_PARAMS_NOT_PRESENT);
  108. m_hwndSpin = GetDlgItem(IDD_PARAMS_SPIN);
  109. Assert(m_hwndSpin);
  110. m_hwndPresentText = GetDlgItem(IDD_PARAMS_PRESENT_TEXT);
  111. Assert(m_hwndPresentText);
  112. // Fill the parameter list box
  113. FillParamListbox();
  114. // No current selection
  115. m_pparam = NULL;
  116. // Clear the initial params value
  117. m_vCurrent.Init(VALUETYPE_INT,0);
  118. // Check if there are any parameters
  119. if (m_plbParams->GetCount() > 0)
  120. {
  121. // Select the first item
  122. m_plbParams->SetCurSel(0);
  123. SelectParam();
  124. }
  125. m_fInitializing = FALSE;
  126. return 0;
  127. }
  128. LRESULT CAdvanced::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  129. {
  130. HRESULT hr = S_OK;
  131. if (FValidateCurrParam())
  132. {
  133. // Show the saved value
  134. UpdateParamDisplay();
  135. Apply();
  136. }
  137. TraceError("CAdvanced::OnApply",hr);
  138. return LresFromHr(hr);
  139. }
  140. LRESULT CAdvanced::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  141. {
  142. HRESULT hr = S_OK;
  143. if (!FValidateCurrParam())
  144. {
  145. // Problems with validation. Keep page from deactivating.
  146. hr = E_FAIL;
  147. }
  148. TraceError("CAdvanced::OnKillActive",hr);
  149. return LresFromHr(hr);
  150. }
  151. LRESULT CAdvanced::OnEdit(WORD wNotifyCode, WORD wID,
  152. HWND hWndCtl, BOOL& fHandled)
  153. {
  154. HRESULT hr = S_OK;
  155. // If the edit box contents have changed, call BeginEdit
  156. if (wNotifyCode == EN_CHANGE)
  157. {
  158. BeginEdit();
  159. }
  160. TraceError("CAdvanced::OnEdit", hr);
  161. return LresFromHr(hr);
  162. }
  163. LRESULT CAdvanced::OnDrop(WORD wNotifyCode, WORD wID,
  164. HWND hWndCtl, BOOL& fHandled)
  165. {
  166. HRESULT hr = S_OK;
  167. // If the combo box contents have changed and we are not initializing
  168. // (i.e. the user changed it, we didn't) then notify the property
  169. // sheet
  170. if ((wNotifyCode == CBN_SELCHANGE) && !m_fInitializing)
  171. {
  172. // selection in dropdownbox has changed
  173. SetChangedFlag();
  174. BeginEdit();
  175. }
  176. TraceError("CAdvanced::OnDrop", hr);
  177. return LresFromHr(hr);
  178. }
  179. LRESULT CAdvanced::OnPresent(WORD wNotifyCode, WORD wID,
  180. HWND hWndCtl, BOOL& fHandled)
  181. {
  182. HRESULT hr = S_OK;
  183. if ((wID == IDD_PARAMS_PRESENT && !m_pbmPresent->GetCheck()) ||
  184. (wID == IDD_PARAMS_NOT_PRESENT && !m_pbmNotPresent->GetCheck() ))
  185. {
  186. // selection has changed
  187. // change the value
  188. if (wID == IDD_PARAMS_PRESENT)
  189. {
  190. m_vCurrent.SetPresent(TRUE);
  191. }
  192. else
  193. {
  194. GetParamValue();
  195. m_vCurrent.SetPresent(FALSE);
  196. }
  197. // Update the value
  198. UpdateParamDisplay();
  199. }
  200. TraceError("CAdvanced::OnPresent", hr);
  201. return LresFromHr(hr);
  202. }
  203. LRESULT CAdvanced::OnList(WORD wNotifyCode, WORD wID,
  204. HWND hWndCtl, BOOL& fHandled)
  205. {
  206. LRESULT lr = 0;
  207. // Changes the listbox selection. If current value is not
  208. // valid, then the selection is not changed.
  209. // Work to do only if selection changes
  210. if (wNotifyCode == LBN_SELCHANGE)
  211. {
  212. // Accept the current value.
  213. // If it isn't valid, change the selection back
  214. if (!FValidateCurrParam())
  215. {
  216. m_plbParams->SetCurSel(m_plbParams->FindItemData(0, m_pparam));
  217. // We handled things so set lr to 1;
  218. lr = 1;
  219. }
  220. else
  221. {
  222. // Select the new param
  223. SelectParam();
  224. }
  225. }
  226. return lr;
  227. }
  228. //+---------------------------------------------------------------------------
  229. //
  230. // Member: CAdvanced::OnDestroy
  231. //
  232. // Purpose: Handles the WM_DESTROY message. Does general memory
  233. // releasing and registry key closing. See ATL docs.
  234. //
  235. // Author: t-nabilr 06 Apr 1997
  236. //
  237. // Notes:
  238. //
  239. LRESULT CAdvanced::OnDestroy(UINT uMsg, WPARAM wParam,
  240. LPARAM lParam, BOOL& fHandled)
  241. {
  242. HRESULT hr = S_OK;
  243. int cItems, iItem;
  244. WCHAR * sz;
  245. // Clean up memory from list boxes
  246. AssertSz(m_pcbxDrop, "Combo box should have been created!");
  247. cItems = m_pcbxDrop->GetCount();
  248. for (iItem=0; iItem < cItems; iItem++)
  249. {
  250. sz = static_cast<WCHAR *>(m_pcbxDrop->GetItemData(iItem));
  251. delete sz;
  252. }
  253. m_pcbxDrop->ResetContent();
  254. // Clean up
  255. m_vCurrent.Destroy();
  256. // Clean up window elements
  257. delete m_plbParams;
  258. m_plbParams = NULL;
  259. delete m_pedtEdit;
  260. m_pedtEdit = NULL;
  261. delete m_pcbxDrop;
  262. m_pcbxDrop = NULL;
  263. delete m_pbmPresent;
  264. m_pbmPresent = NULL;
  265. delete m_pbmNotPresent;
  266. m_pbmNotPresent = NULL;
  267. TraceError("CAdvanced::OnDestroy",hr);
  268. return LresFromHr(hr);
  269. }
  270. //+---------------------------------------------------------------------------
  271. //
  272. // Member: CAdvanced::OnHelp
  273. //
  274. // Purpose: Handler for the WM_HELP windows message.
  275. //
  276. // Author: BillBe 01 Jul 1998
  277. //
  278. // Notes:
  279. //
  280. //
  281. LRESULT CAdvanced::OnHelp(UINT uMsg, WPARAM wParam,
  282. LPARAM lParam, BOOL& fHandled)
  283. {
  284. LRESULT lr = 0;
  285. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  286. Assert(lphi);
  287. if (HELPINFO_WINDOW == lphi->iContextType)
  288. {
  289. ::WinHelp(static_cast<HWND>(lphi->hItemHandle), c_szDevMgrHelpFile,
  290. HELP_WM_HELP, reinterpret_cast<UINT_PTR>(g_aHelpIds));
  291. lr = 1;
  292. }
  293. return lr;
  294. }
  295. LRESULT CAdvanced::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam,
  296. BOOL& fHandled)
  297. {
  298. ::WinHelp(reinterpret_cast<HWND>(wParam), c_szDevMgrHelpFile,
  299. HELP_CONTEXTMENU, reinterpret_cast<UINT_PTR>(g_aHelpIds));
  300. return TRUE;
  301. }
  302. CAdvanced::~CAdvanced()
  303. {
  304. }
  305. //+---------------------------------------------------------------------------
  306. //
  307. // Member: CAdvanced::Apply
  308. //
  309. // Purpose: Applies values from InMemory storage. to the registry
  310. //
  311. // Author: t-nabilr 06 Apr 1997
  312. //
  313. // Notes:
  314. //
  315. VOID CAdvanced::Apply()
  316. {
  317. if (FSave())
  318. {
  319. SP_DEVINSTALL_PARAMS deip;
  320. // Set the properties change flag in the device info to
  321. // let the property page host know that the property change function
  322. // shuld be sent to the driver
  323. // We can't let any failures here stop us so we ignore
  324. // return values
  325. (void) HrSetupDiGetDeviceInstallParams(m_hdi, m_pdeid, &deip);
  326. deip.FlagsEx |= DI_FLAGSEX_PROPCHANGE_PENDING;
  327. (void) HrSetupDiSetDeviceInstallParams(m_hdi, m_pdeid, &deip);
  328. }
  329. }
  330. //+---------------------------------------------------------------------------
  331. //
  332. // Member: CAdvanced::FillParamListbox
  333. //
  334. // Purpose: Populates the UI's parameter listbox using the parameters
  335. // from m_listpParam.
  336. //
  337. // Author: t-nabilr 06 Apr 1997
  338. //
  339. // Notes:
  340. //
  341. VOID CAdvanced::FillParamListbox()
  342. {
  343. vector<CParam *>::iterator ppParam;
  344. INT iItem;
  345. WCHAR szRegValue[c_cchMaxRegStrLen];
  346. m_plbParams->ResetContent();
  347. for (ppParam = m_listpParam.begin(); ppParam != m_listpParam.end();
  348. ppParam++)
  349. {
  350. Assert (*ppParam != NULL);
  351. // Get text string
  352. (*ppParam)->GetDescription(szRegValue,celems(szRegValue));
  353. // Add the description string to the listbox
  354. iItem = m_plbParams->AddString(szRegValue);
  355. if (iItem >= 0)
  356. {
  357. m_plbParams->SetItemData(iItem,*ppParam);
  358. }
  359. }
  360. }
  361. //
  362. // FValidateCurrParam
  363. //
  364. // Purpose:
  365. // Validates the current parameter. Displays UI and reverts back to
  366. // original value on error.
  367. //
  368. // Parameters:
  369. // None - validates the param currently being edited.
  370. //
  371. // Notes:
  372. // How is this different from FValidateSingleParam? This function
  373. // is intended to be used when the user is interacting with the
  374. // current param. If there's an error with the current parameter,
  375. // the parameter is reverted back to it's old value (before the user's
  376. // changes).
  377. //$ REVIEW (t-nabilr) Is it good to revert the user's changes on error?
  378. // (see above)
  379. //
  380. BOOL CAdvanced::FValidateCurrParam()
  381. {
  382. CValue vPrevious;
  383. BOOL fRetval = FALSE;
  384. // Save the previous param value - so we can restore it
  385. // if the control value is invalid
  386. vPrevious.InitNotPresent(m_pparam->GetType());
  387. vPrevious.Copy(m_pparam->GetValue());
  388. // Get the current control value and validate it
  389. GetParamValue();
  390. m_pparam->GetValue()->Copy(&m_vCurrent);
  391. if (FValidateSingleParam(m_pparam, TRUE, m_hWnd))
  392. {
  393. // Update the modified bit
  394. m_pparam->SetModified(
  395. (m_pparam->GetValue()->Compare(m_pparam->GetInitial()) != 0));
  396. fRetval = TRUE;
  397. }
  398. // Restore the original value if there was an error
  399. if (!fRetval)
  400. m_pparam->GetValue()->Copy(&vPrevious);
  401. // Cleanup
  402. vPrevious.Destroy();
  403. return fRetval;
  404. }
  405. // UpdateDisplay
  406. //
  407. // Purpose:
  408. // Sets up the screen to display -- and displays -- the current param.
  409. // Changes the UI's control type, etc.
  410. //
  411. VOID CAdvanced::UpdateDisplay()
  412. {
  413. int cItems;
  414. WCHAR * psz;
  415. // Clean up memory from list boxes
  416. cItems = m_pcbxDrop->GetCount();
  417. for (int iItem=0; iItem < cItems; iItem++)
  418. {
  419. psz = (WCHAR *)m_pcbxDrop->GetItemData(iItem);
  420. delete psz;
  421. }
  422. m_pcbxDrop->ResetContent();
  423. // set appropriate Control Type
  424. switch (m_pparam->GetType())
  425. {
  426. case VALUETYPE_ENUM:
  427. m_ctlControlType = CTLTYPE_DROP;
  428. break;
  429. case VALUETYPE_EDIT:
  430. m_ctlControlType = CTLTYPE_EDIT;
  431. break;
  432. case VALUETYPE_DWORD:
  433. // The spin control only fits up to signed 32-bit values
  434. // So we must use an edit control for larger numbers
  435. if (m_pparam->GetMax()->GetDword() > LONG_MAX)
  436. {
  437. m_ctlControlType = CTLTYPE_EDIT;
  438. }
  439. else
  440. {
  441. m_ctlControlType = CTLTYPE_SPIN;
  442. }
  443. break;
  444. case VALUETYPE_KONLY:
  445. m_ctlControlType = CTLTYPE_NONE;
  446. break;
  447. default:
  448. m_ctlControlType = CTLTYPE_SPIN;
  449. }
  450. // Hide all controls
  451. m_pedtEdit->Show(FALSE);
  452. m_pcbxDrop->Show(FALSE);
  453. ::ShowWindow(m_hwndSpin,SW_HIDE);
  454. ::ShowWindow(m_hwndPresentText,SW_HIDE);
  455. // Show the appropriate control
  456. switch (m_ctlControlType)
  457. {
  458. case CTLTYPE_EDIT:
  459. m_pedtEdit->Show(TRUE);
  460. break;
  461. case CTLTYPE_DROP:
  462. m_pcbxDrop->Show(TRUE);
  463. break;
  464. case CTLTYPE_SPIN:
  465. m_pedtEdit->Show(TRUE);
  466. ::ShowWindow(m_hwndSpin,SW_NORMAL);
  467. break;
  468. case CTLTYPE_NONE:
  469. ::ShowWindow(m_hwndPresentText,SW_NORMAL);
  470. break;
  471. default:
  472. AssertSz(FALSE, "Invalid Control Type");
  473. }
  474. // Show the "optional" radio buttons
  475. if (m_pparam->FIsOptional())
  476. {
  477. m_pbmPresent->Show(TRUE);
  478. m_pbmNotPresent->Show(TRUE);
  479. }
  480. else
  481. {
  482. m_pbmPresent->Show(FALSE);
  483. m_pbmNotPresent->Show(FALSE);
  484. }
  485. SetParamRange();
  486. // show the param's value
  487. UpdateParamDisplay();
  488. }
  489. //+---------------------------------------------------------------------------
  490. //
  491. // Member: CAdvanced::SelectParam
  492. //
  493. // Purpose: Takes the parameter selection from the listbox
  494. // and makes it the current parameter. The display is updated
  495. // to show the newly selected parameter.
  496. //
  497. // Author: t-nabilr 06 Apr 1997
  498. //
  499. // Notes:
  500. //
  501. VOID CAdvanced::SelectParam()
  502. {
  503. int nCurSel;
  504. register CParam *pparam;
  505. int cItems, iItem;
  506. PSTR psz;
  507. // Determine the new parameter list selection
  508. nCurSel = m_plbParams->GetCurSel();
  509. if (nCurSel >= 0)
  510. {
  511. // Get the new current parameter
  512. pparam = (CParam *)m_plbParams->GetItemData(nCurSel);
  513. Assert(pparam != NULL);
  514. // only do work if it's not the same parameter.
  515. if (pparam != m_pparam)
  516. {
  517. m_pparam = pparam;
  518. m_vCurrent.Destroy();
  519. m_vCurrent.InitNotPresent(m_pparam->GetType());
  520. m_vCurrent.Copy(m_pparam->GetValue());
  521. // show the param
  522. UpdateDisplay();
  523. }
  524. }
  525. }
  526. //+---------------------------------------------------------------------------
  527. //
  528. // Member: CAdvanced::SetParamRange
  529. //
  530. // Purpose:
  531. // Sets "range" values for the current param, depending on it's type.
  532. // For enum values, it reads the enums into a dropbox.
  533. // For spin control, it sets the min/max and acceleration values.
  534. // For edit box, it sets the edit style.
  535. //
  536. // Author: t-nabilr 06 Apr 1997
  537. //
  538. // Notes:
  539. //
  540. VOID CAdvanced::SetParamRange()
  541. {
  542. DWORD cbValue;
  543. DWORD dwType;
  544. DWORD dwStyle;
  545. DWORD iValue;
  546. int iItem;
  547. #define NUM_UDACCELS 3
  548. UDACCEL aUDAccel[NUM_UDACCELS];
  549. UINT uBase;
  550. WCHAR * pszValueName;
  551. WCHAR szRegValueName[c_cchMaxRegStrLen];
  552. DWORD cchRegValueName;
  553. WCHAR szRegValue[c_cchMaxRegStrLen];
  554. HRESULT hr = S_OK;
  555. // We are initializing so we need to set a flag so the UI doesn't think
  556. // it's the user who is changing things
  557. m_fInitializing = TRUE;
  558. switch (m_ctlControlType)
  559. {
  560. case CTLTYPE_DROP:
  561. // Reset the combobox
  562. m_pcbxDrop->ResetContent();
  563. for (iValue = 0; SUCCEEDED(hr); iValue++)
  564. {
  565. cchRegValueName = celems(szRegValueName);
  566. cbValue = sizeof(szRegValue);
  567. hr = HrRegEnumValue(m_pparam->GetEnumKey(), iValue, szRegValueName,
  568. &cchRegValueName,
  569. &dwType, (BYTE *)szRegValue, &cbValue);
  570. if (SUCCEEDED(hr) && dwType == REG_SZ)
  571. {
  572. TraceTag(ttidNetComm, "Enum String %S index %d",
  573. szRegValueName, iValue);
  574. // Got the next registry value, and it's a string.
  575. pszValueName = new WCHAR[wcslen(szRegValueName) + 1];
  576. if (pszValueName == NULL)
  577. {
  578. break;
  579. }
  580. lstrcpyW(pszValueName,szRegValueName);
  581. // Add the text string
  582. iItem = m_pcbxDrop->AddString(szRegValue);
  583. if (iItem >= 0)
  584. {
  585. m_pcbxDrop->SetItemData(iItem,pszValueName);
  586. }
  587. else
  588. {
  589. delete pszValueName;
  590. }
  591. }
  592. }
  593. break;
  594. case CTLTYPE_SPIN:
  595. int nStep;
  596. int nMin;
  597. int nMax;
  598. // Set the numeric base
  599. uBase = m_pparam->GetValue()->IsHex() ? 16 : 10;
  600. ::SendMessage(m_hwndSpin,UDM_SETBASE,(WPARAM)uBase,0L);
  601. nStep = m_pparam->GetStep()->GetNumericValueAsDword();
  602. nMin = m_pparam->GetMin()->GetNumericValueAsSignedInt();
  603. nMax = m_pparam->GetMax()->GetNumericValueAsSignedInt();
  604. ::SendMessage(m_hwndSpin,UDM_SETRANGE32, nMin, nMax);
  605. // Set the range-accelerator values
  606. aUDAccel[0].nSec = 0;
  607. aUDAccel[0].nInc = nStep;
  608. aUDAccel[1].nSec = 1;
  609. aUDAccel[1].nInc = 2 * nStep;
  610. aUDAccel[2].nSec = 3;
  611. aUDAccel[2].nInc = uBase * nStep;
  612. ::SendMessage(m_hwndSpin, UDM_SETACCEL,NUM_UDACCELS,
  613. (LPARAM)(LPUDACCEL)aUDAccel);
  614. break;
  615. case CTLTYPE_EDIT:
  616. m_pedtEdit->LimitText(m_pparam->GetLimitText());
  617. dwStyle = m_pedtEdit->GetStyle();
  618. if (m_pparam->FIsUppercase())
  619. dwStyle |= ES_UPPERCASE;
  620. else
  621. dwStyle &= ~ES_UPPERCASE;
  622. if (m_pparam->FIsOEMText())
  623. dwStyle |= ES_OEMCONVERT;
  624. else
  625. dwStyle &= ~ES_OEMCONVERT;
  626. if (m_pparam->FIsReadOnly())
  627. dwStyle |= ES_READONLY;
  628. else
  629. dwStyle &= ~ES_READONLY;
  630. m_pedtEdit->SetStyle(dwStyle);
  631. break;
  632. case CTLTYPE_NONE:
  633. break;
  634. default:
  635. AssertSz(FALSE,"Hit default case in CAdvanced::SetParamRange");
  636. }
  637. m_fInitializing = FALSE;
  638. }
  639. //+---------------------------------------------------------------------------
  640. //
  641. // Member: CAdvanced::UpdateParamDisplay
  642. //
  643. // Purpose: Updates the value of the parameter on the UI. Used when
  644. // the param value has progmatically changed, and needs to be
  645. // updated on the UI.
  646. //
  647. // Author: t-nabilr 06 Apr 1997
  648. //
  649. // Notes: You could use UpdateDisplay to refresh the param value, but
  650. // UpdateDisplay() does a lot of extra work such as setting
  651. // the control type. (BTW, UpdateDisplay calls
  652. // UpdateParamDisplay().)
  653. //
  654. VOID CAdvanced::UpdateParamDisplay() // was SetParam
  655. {
  656. WCHAR szValue[VALUE_SZMAX];
  657. int iItem;
  658. // We are initializing so we need to set a flag so the UI doesn't think
  659. // it's the user who is changing things
  660. m_fInitializing = TRUE;
  661. // Set present/not present radio button.
  662. // If an optional value is not present, clear the control and return.
  663. Assert(m_pparam);
  664. if (m_pparam->FIsOptional())
  665. {
  666. m_pbmPresent->SetCheck(m_vCurrent.IsPresent());
  667. m_pbmNotPresent->SetCheck(!m_vCurrent.IsPresent());
  668. }
  669. // Show/Hide the parameter
  670. if (!m_pparam->FIsOptional() || m_vCurrent.IsPresent())
  671. {
  672. // Show the value
  673. switch (m_ctlControlType)
  674. {
  675. case CTLTYPE_SPIN:
  676. {
  677. // The spin control message UDM_SETPOS only handles 16-bit
  678. // numbers even though the control can handle 32 bit ranges.
  679. // This means we need to set the number by using the buddy
  680. // window.
  681. //
  682. WCHAR szNumber[c_cchMaxNumberSize];
  683. m_vCurrent.ToString(szNumber, c_cchMaxNumberSize);
  684. HWND hwndBuddy = reinterpret_cast<HWND>(::SendMessage(m_hwndSpin,
  685. UDM_GETBUDDY,
  686. 0,
  687. 0));
  688. ::SetWindowText(hwndBuddy, szNumber);
  689. }
  690. break;
  691. case CTLTYPE_DROP:
  692. iItem = EnumvalToItem(m_vCurrent.GetPsz());
  693. m_pcbxDrop->SetCurSel(iItem);
  694. break;
  695. case CTLTYPE_EDIT:
  696. m_vCurrent.ToString(szValue,VALUE_SZMAX);
  697. m_pedtEdit->SetText(szValue);
  698. break;
  699. case CTLTYPE_NONE:
  700. break;
  701. default:
  702. AssertSz(FALSE,"Invalid control type in function UpdateParamDisplay");
  703. }
  704. }
  705. else
  706. {
  707. // Hide the value
  708. switch (m_ctlControlType)
  709. {
  710. case CTLTYPE_EDIT:
  711. case CTLTYPE_SPIN:
  712. m_pedtEdit->SetText(L"");
  713. break;
  714. case CTLTYPE_DROP:
  715. m_pcbxDrop->SetCurSel(CB_ERR);
  716. break;
  717. case CTLTYPE_NONE:
  718. break;
  719. default:
  720. Assert(FALSE); //DEBUG_TRAP;
  721. }
  722. }
  723. // Remove inhibition
  724. m_fInitializing = FALSE;
  725. }
  726. //+---------------------------------------------------------------------------
  727. //
  728. // Member: CAdvanced::GetParamValue
  729. //
  730. // Purpose: Gets the value of the current parameter from the UI and puts
  731. // in in m_vCurrent.
  732. //
  733. // Author: t-nabilr 06 Apr 1997
  734. //
  735. // Notes:
  736. //
  737. VOID CAdvanced::GetParamValue()
  738. {
  739. WCHAR szValue[VALUE_SZMAX];
  740. int iItem;
  741. // Get the "present" value for an optional param
  742. if (m_pparam->FIsOptional() && !m_pbmPresent->GetCheck())
  743. {
  744. m_vCurrent.SetPresent(FALSE);
  745. // Not present - don't read the control value
  746. return;
  747. }
  748. // The value is present
  749. m_vCurrent.SetPresent(TRUE);
  750. // Get the control value
  751. switch (m_ctlControlType)
  752. {
  753. case CTLTYPE_SPIN:
  754. {
  755. // The spin control can handle 32-bit ranges but the message
  756. // UDM_GETPOS will only return a 16-bit number. This means we
  757. // should get the number from the buddy window if we want the
  758. // exact value.
  759. //
  760. WCHAR szBuffer[c_cchMaxNumberSize];
  761. HWND hwndBuddy = reinterpret_cast<HWND>(::SendMessage(m_hwndSpin,
  762. UDM_GETBUDDY,
  763. 0,
  764. 0));
  765. ::GetWindowText(hwndBuddy, szBuffer, c_cchMaxNumberSize);
  766. m_vCurrent.FromString(szBuffer);
  767. }
  768. break;
  769. case CTLTYPE_EDIT:
  770. m_pedtEdit->GetText(szValue, VALUE_SZMAX);
  771. m_vCurrent.FromString(szValue);
  772. break;
  773. case CTLTYPE_DROP:
  774. iItem = m_pcbxDrop->GetCurSel();
  775. if (iItem == CB_ERR)
  776. break;
  777. ItemToEnumval(iItem,szValue,VALUE_SZMAX);
  778. m_vCurrent.FromString(szValue);
  779. break;
  780. case CTLTYPE_NONE:
  781. break; // No data to return (present/not present is all were interested in)
  782. default:
  783. Assert(FALSE);// DEBUG_TRAP;
  784. }
  785. return;
  786. }
  787. //+---------------------------------------------------------------------------
  788. //
  789. // Member: CAdvanced::EnumvalToItem
  790. //
  791. // Purpose: Converts a combobox string into an integer representing the
  792. // location withing the drop down combobox (for enums).
  793. //
  794. // Arguments:
  795. // psz [in] string to look for.
  796. //
  797. // Returns: Combobox item number where this string can be found.
  798. //
  799. // Author: t-nabilr 06 Apr 1997
  800. //
  801. // Notes:
  802. //
  803. int CAdvanced::EnumvalToItem(const PWSTR psz)
  804. {
  805. int cItems;
  806. int iItem;
  807. PWSTR pszValueName;
  808. Assert(m_pparam->GetType() == VALUETYPE_ENUM);
  809. cItems = m_pcbxDrop->GetCount();
  810. for (iItem = 0; iItem < cItems; iItem++)
  811. {
  812. pszValueName = (PWSTR)m_pcbxDrop->GetItemData (iItem);
  813. if (lstrcmpiW (pszValueName,psz) == 0)
  814. {
  815. return iItem;
  816. }
  817. }
  818. // Not found.
  819. return 0;
  820. }
  821. //+---------------------------------------------------------------------------
  822. //
  823. // Member: CAdvanced::ItemToEnumval
  824. //
  825. // Purpose: Converts the item number within the combobox dropdown
  826. // into a string.
  827. //
  828. // Arguments:
  829. // iItem [in] item number within combobox.
  830. // psz [out] ptr to string to populate
  831. // cch [in] length (characters) of psz buffer.
  832. //
  833. // Returns: length of string (# of characters) put in psz.
  834. //
  835. // Author: t-nabilr 06 Apr 1997
  836. //
  837. // Notes:
  838. //
  839. int CAdvanced::ItemToEnumval(int iItem, PWSTR psz, UINT cch)
  840. {
  841. PWSTR pszValueName;
  842. pszValueName = (PWSTR)m_pcbxDrop->GetItemData (iItem);
  843. if ((PWSTR)CB_ERR == pszValueName)
  844. {
  845. return 0;
  846. }
  847. lstrcpynW (psz,pszValueName,cch);
  848. return lstrlenW (psz);
  849. }
  850. //+---------------------------------------------------------------------------
  851. //
  852. // Member: CAdvanced::
  853. //
  854. // Purpose:
  855. //
  856. // Arguments:
  857. // nID [in] ID of thingy.
  858. // fInstall [in] TRUE if installing, FALSE otherwise.
  859. // ppv [in,out] Old value is freed and this returns new value.
  860. //
  861. // Returns:
  862. //
  863. // Author: t-nabilr 06 Apr 1997
  864. //
  865. // Notes:
  866. //
  867. VOID CAdvanced::BeginEdit()
  868. {
  869. // Check if we need to update the radio buttons
  870. if (!m_fInitializing)
  871. {
  872. SetChangedFlag();
  873. if (m_vCurrent.IsPresent() == FALSE)
  874. {
  875. // we've begun editing, so select the present radiobutton
  876. m_vCurrent.SetPresent(TRUE);
  877. m_pbmPresent->SetCheck(1);
  878. m_pbmNotPresent->SetCheck(0);
  879. }
  880. }
  881. }
  882. //+---------------------------------------------------------------------------
  883. //
  884. // Function: HrGetAdvancedPage
  885. //
  886. // Purpose: Creates the advanced page for enumerated net devices
  887. // This is called by NetPropPageProvider
  888. //
  889. // Arguments:
  890. // hdi [in] See SetupApi for info
  891. // pdeid [in] See SetupApi for for info
  892. // phpsp [out] Pointer to the handle to the advanced property page
  893. //
  894. // Returns:
  895. //
  896. // Author: billbe 24 June 1997
  897. //
  898. // Notes:
  899. //
  900. HRESULT
  901. HrGetAdvancedPage(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  902. HPROPSHEETPAGE* phpsp)
  903. {
  904. Assert(hdi);
  905. Assert(pdeid);
  906. Assert(phpsp);
  907. HRESULT hr;
  908. HPROPSHEETPAGE hpsp;
  909. CAdvanced* padv = new CAdvanced();
  910. // create the advanced page
  911. hpsp = padv->CreatePage(hdi, pdeid);
  912. // if successful set the out param
  913. if (hpsp)
  914. {
  915. *phpsp = hpsp;
  916. hr = S_OK;
  917. }
  918. else
  919. {
  920. // Either there is no advanced page to display or there
  921. // was an error.
  922. hr = E_FAIL;
  923. *phpsp = NULL;
  924. delete padv;
  925. }
  926. TraceErrorOptional("HrGetAdvancedPage", hr, E_FAIL == hr);
  927. return hr;
  928. }