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.

575 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A C B I N D . C P P
  7. //
  8. // Contents: Advanced configuration bindings dialog implementation
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 18 Nov 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "acbind.h"
  18. #include "achelp.h"
  19. #include "acsheet.h"
  20. #include "connutil.h"
  21. #include "lancmn.h"
  22. #include "ncnetcfg.h"
  23. #include "ncsetup.h"
  24. #include "ncui.h"
  25. #include "netconp.h"
  26. #include "order.h"
  27. const DWORD g_aHelpIDs_IDD_ADVCFG_Bindings[]=
  28. {
  29. LVW_Adapters, IDH_Adapters,
  30. PSB_Adapter_Up, IDH_Adapter_Up,
  31. PSB_Adapter_Down, IDH_Adapter_Down,
  32. TVW_Bindings, IDH_Bindings,
  33. PSB_Binding_Up, IDH_Binding_Up,
  34. IDH_Binding_Down, PSB_Binding_Down,
  35. 0,0
  36. };
  37. extern const WCHAR c_szNetCfgHelpFile[];
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Member: CBindingsDlg::~CBindingsDlg
  41. //
  42. // Purpose: Destructor for the Advanced configuration dialog
  43. //
  44. // Arguments:
  45. // (none)
  46. //
  47. // Returns: Nothing
  48. //
  49. // Author: danielwe 26 Nov 1997
  50. //
  51. // Notes:
  52. //
  53. CBindingsDlg::~CBindingsDlg()
  54. {
  55. if (m_hiconUpArrow)
  56. {
  57. DeleteObject(m_hiconUpArrow);
  58. }
  59. if (m_hiconDownArrow)
  60. {
  61. DeleteObject(m_hiconDownArrow);
  62. }
  63. if (m_hilItemIcons)
  64. {
  65. ImageList_Destroy(m_hilItemIcons);
  66. }
  67. if (m_hilCheckIcons)
  68. {
  69. ImageList_Destroy(m_hilCheckIcons);
  70. }
  71. ReleaseObj(m_pnc);
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Member: CBindingsDlg::OnInitDialog
  76. //
  77. // Purpose: Called when the WM_INITDIALOG is received
  78. //
  79. // Arguments:
  80. // uMsg []
  81. // wParam []
  82. // lParam []
  83. // bHandled []
  84. //
  85. // Returns:
  86. //
  87. // Author: danielwe 19 Nov 1997
  88. //
  89. // Notes:
  90. //
  91. LRESULT CBindingsDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  92. LPARAM lParam, BOOL& bHandled)
  93. {
  94. HRESULT hr = S_OK;
  95. INT iaci;
  96. RECT rc;
  97. LV_COLUMN lvc = {0};
  98. SP_CLASSIMAGELIST_DATA cid;
  99. m_hwndLV = GetDlgItem(LVW_Adapters);
  100. m_hwndTV = GetDlgItem(TVW_Bindings);
  101. // Make this initially invisible in case we don't have any adapters
  102. ::ShowWindow(GetDlgItem(IDH_TXT_ADVGFG_BINDINGS), SW_HIDE);
  103. hr = HrSetupDiGetClassImageList(&cid);
  104. if (SUCCEEDED(hr))
  105. {
  106. // Create small image lists
  107. m_hilItemIcons = ImageList_Duplicate(cid.ImageList);
  108. // Add the LAN connection icon to the image list
  109. HICON hIcon = LoadIcon(_Module.GetResourceInstance(),
  110. MAKEINTRESOURCE(IDI_LB_GEN_S_16));
  111. Assert(hIcon);
  112. // Add the icon
  113. m_nIndexLan = ImageList_AddIcon(m_hilItemIcons, hIcon);
  114. ListView_SetImageList(m_hwndLV, m_hilItemIcons, LVSIL_SMALL);
  115. TreeView_SetImageList(m_hwndTV, m_hilItemIcons, TVSIL_NORMAL);
  116. (void) HrSetupDiDestroyClassImageList(&cid);
  117. }
  118. ::GetClientRect(m_hwndLV, &rc);
  119. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  120. lvc.fmt = LVCFMT_LEFT;
  121. lvc.cx = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  122. ListView_InsertColumn(m_hwndLV, 0, &lvc);
  123. if (!m_hiconUpArrow && !m_hiconDownArrow)
  124. {
  125. m_hiconUpArrow = (HICON)LoadImage(_Module.GetResourceInstance(),
  126. MAKEINTRESOURCE(IDI_UP_ARROW),
  127. IMAGE_ICON, 16, 16, 0);
  128. m_hiconDownArrow = (HICON)LoadImage(_Module.GetResourceInstance(),
  129. MAKEINTRESOURCE(IDI_DOWN_ARROW),
  130. IMAGE_ICON, 16, 16, 0);
  131. }
  132. SendDlgItemMessage(PSB_Adapter_Up, BM_SETIMAGE, IMAGE_ICON,
  133. reinterpret_cast<LPARAM>(m_hiconUpArrow));
  134. SendDlgItemMessage(PSB_Adapter_Down, BM_SETIMAGE, IMAGE_ICON,
  135. reinterpret_cast<LPARAM>(m_hiconDownArrow));
  136. SendDlgItemMessage(PSB_Binding_Up, BM_SETIMAGE, IMAGE_ICON,
  137. reinterpret_cast<LPARAM>(m_hiconUpArrow));
  138. SendDlgItemMessage(PSB_Binding_Down, BM_SETIMAGE, IMAGE_ICON,
  139. reinterpret_cast<LPARAM>(m_hiconDownArrow));
  140. if (SUCCEEDED(hr))
  141. {
  142. hr = HrBuildAdapterList();
  143. }
  144. // Create state image lists
  145. m_hilCheckIcons = ImageList_LoadBitmapAndMirror(
  146. _Module.GetResourceInstance(),
  147. MAKEINTRESOURCE(IDB_CHECKSTATE),
  148. 16,
  149. 0,
  150. PALETTEINDEX(6));
  151. TreeView_SetImageList(m_hwndTV, m_hilCheckIcons, TVSIL_STATE);
  152. if (FAILED(hr))
  153. {
  154. SetWindowLong(DWLP_MSGRESULT, PSNRET_INVALID);
  155. }
  156. return TRUE;
  157. }
  158. //+---------------------------------------------------------------------------
  159. //
  160. // Member: CBindingsDlg::OnContextMenu
  161. //
  162. // Purpose: Called in response to the WM_CONTEXTMENU message
  163. //
  164. // Arguments:
  165. // uMsg []
  166. // wParam []
  167. // lParam []
  168. // bHandled []
  169. //
  170. // Returns: 0 always
  171. //
  172. // Author: danielwe 22 Jan 1998
  173. //
  174. // Notes:
  175. //
  176. LRESULT CBindingsDlg::OnContextMenu(UINT uMsg, WPARAM wParam,
  177. LPARAM lParam, BOOL& bHandled)
  178. {
  179. ::WinHelp(m_hWnd,
  180. c_szNetCfgHelpFile,
  181. HELP_CONTEXTMENU,
  182. reinterpret_cast<ULONG_PTR>(g_aHelpIDs_IDD_ADVCFG_Bindings));
  183. return 0;
  184. }
  185. //+---------------------------------------------------------------------------
  186. //
  187. // Member: CBindingsDlg::OnHelp
  188. //
  189. // Purpose: Called in response to the WM_HELP message
  190. //
  191. // Arguments:
  192. // uMsg []
  193. // wParam []
  194. // lParam []
  195. // bHandled []
  196. //
  197. // Returns: TRUE
  198. //
  199. // Author: danielwe 19 Mar 1998
  200. //
  201. // Notes:
  202. //
  203. LRESULT CBindingsDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  204. BOOL& bHandled)
  205. {
  206. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  207. if (HELPINFO_WINDOW == lphi->iContextType)
  208. {
  209. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  210. c_szNetCfgHelpFile,
  211. HELP_WM_HELP,
  212. reinterpret_cast<ULONG_PTR>(g_aHelpIDs_IDD_ADVCFG_Bindings));
  213. }
  214. return TRUE;
  215. }
  216. //+---------------------------------------------------------------------------
  217. //
  218. // Member: CBindingsDlg::OnOk
  219. //
  220. // Purpose: Called when the OK button is pressed
  221. //
  222. // Arguments:
  223. //
  224. // Returns:
  225. //
  226. // Author: danielwe 19 Nov 1997
  227. //
  228. // Notes:
  229. //
  230. LRESULT CBindingsDlg::OnOk(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  231. {
  232. CWaitCursor wc;
  233. HRESULT hr = m_pnc->Apply();
  234. if (NETCFG_S_REBOOT == hr)
  235. {
  236. // On a reboot, uninitialize NetCfg since we won't be leaving
  237. // this function.
  238. //
  239. (VOID) m_pnc->Uninitialize();
  240. (VOID) HrNcQueryUserForReboot(_Module.GetResourceInstance(),
  241. m_hWnd,
  242. IDS_ADVCFG_CAPTION,
  243. IDS_REBOOT_REQUIRED,
  244. QUFR_PROMPT | QUFR_REBOOT);
  245. }
  246. // Normalize result
  247. if (S_FALSE == hr)
  248. {
  249. hr = S_OK;
  250. }
  251. TraceError("CBindingsDlg::OnOk", hr);
  252. return LresFromHr(hr);
  253. }
  254. //
  255. // Binding list implementation
  256. //
  257. //+---------------------------------------------------------------------------
  258. //
  259. // Member: CSortableBindPath::operator <
  260. //
  261. // Purpose: Provides comparison operator for binding path depth
  262. //
  263. // Arguments:
  264. // refsbp [in] Reference to bind path to compare with
  265. //
  266. // Returns: TRUE if given bind path depth is greater than this one
  267. //
  268. // Author: danielwe 26 Nov 1997
  269. //
  270. // Notes: The comparison is backwards on purpose so that sorting is
  271. // done is descending order.
  272. //
  273. bool CSortableBindPath::operator<(const CSortableBindPath &refsbp) const
  274. {
  275. DWORD dwLen1;
  276. DWORD dwLen2;
  277. GetDepth(&dwLen1);
  278. refsbp.GetDepth(&dwLen2);
  279. // yes this is greater than because we want to sort in descending order
  280. return dwLen1 > dwLen2;
  281. }
  282. //+---------------------------------------------------------------------------
  283. //
  284. // Function: FIsHidden
  285. //
  286. // Purpose: Returns TRUE if the given component has the NCF_HIDDEN
  287. // characterstic.
  288. //
  289. // Arguments:
  290. // pncc [in] Component to be checked
  291. //
  292. // Returns: TRUE if component is hidden, FALSE if not
  293. //
  294. // Author: danielwe 26 Nov 1997
  295. //
  296. // Notes:
  297. //
  298. BOOL FIsHidden(INetCfgComponent *pncc)
  299. {
  300. DWORD dwFlags;
  301. return (SUCCEEDED(pncc->GetCharacteristics(&dwFlags)) &&
  302. ((dwFlags & NCF_HIDE_BINDING) || (dwFlags & NCF_HIDDEN)));
  303. }
  304. //+---------------------------------------------------------------------------
  305. //
  306. // Function: FDontExposeLower
  307. //
  308. // Purpose: Returns TRUE if the given component has the NCF_DONTEXPOSELOWER
  309. // characterstic.
  310. //
  311. // Arguments:
  312. // pncc [in] Component to be checked
  313. //
  314. // Returns: TRUE if component has DONTEXPOSELOWER, FALSE if not
  315. //
  316. // Author: danielwe 26 Nov 1997
  317. //
  318. // Notes:
  319. //
  320. BOOL FDontExposeLower(INetCfgComponent *pncc)
  321. {
  322. DWORD dwFlags;
  323. return (SUCCEEDED(pncc->GetCharacteristics(&dwFlags)) &&
  324. (dwFlags & NCF_DONTEXPOSELOWER));
  325. }
  326. //+---------------------------------------------------------------------------
  327. //
  328. // Function: HrCountDontExposeLower
  329. //
  330. // Purpose: Counts the number of components in the given binding path
  331. // that have the NCF_DONTEXPOSELOWER characterstic.
  332. //
  333. // Arguments:
  334. // pncbp [in] Binding path to count
  335. // pcItems[out] Number of components in the binding path that have the
  336. // NCF_DONTEXPOSELOWER characterstic.
  337. //
  338. // Returns: S_OK if success, OLE or Win32 error otherwise
  339. //
  340. // Author: danielwe 1 Dec 1997
  341. //
  342. // Notes:
  343. //
  344. HRESULT HrCountDontExposeLower(INetCfgBindingPath *pncbp, DWORD *pcItems)
  345. {
  346. HRESULT hr = S_OK;
  347. CIterNetCfgBindingInterface ncbiIter(pncbp);
  348. INetCfgBindingInterface * pncbi;
  349. DWORD cItems = 0;
  350. DWORD cIter = 0;
  351. Assert(pcItems);
  352. *pcItems = 0;
  353. while (SUCCEEDED(hr) && S_OK == (hr = ncbiIter.HrNext(&pncbi)))
  354. {
  355. INetCfgComponent * pncc;
  356. if (!cIter)
  357. {
  358. // First iteration. Get upper component first.
  359. hr = pncbi->GetUpperComponent(&pncc);
  360. if (SUCCEEDED(hr))
  361. {
  362. if (FDontExposeLower(pncc))
  363. {
  364. cItems++;
  365. }
  366. ReleaseObj(pncc);
  367. }
  368. }
  369. hr = pncbi->GetLowerComponent(&pncc);
  370. if (SUCCEEDED(hr))
  371. {
  372. if (FDontExposeLower(pncc))
  373. {
  374. cItems++;
  375. }
  376. ReleaseObj(pncc);
  377. }
  378. ReleaseObj(pncbi);
  379. }
  380. if (SUCCEEDED(hr))
  381. {
  382. *pcItems = cItems;
  383. hr = S_OK;
  384. }
  385. TraceError("HrCountDontExposeLower", hr);
  386. return hr;
  387. }
  388. //+---------------------------------------------------------------------------
  389. //
  390. // Function: FEqualComponents
  391. //
  392. // Purpose: Compares the given 2 components to see if they are the same
  393. //
  394. // Arguments:
  395. // pnccA [in] First component to compare
  396. // pnccB [in] Second component to compare
  397. //
  398. // Returns: TRUE if components are the same, FALSE if not
  399. //
  400. // Author: danielwe 1 Dec 1997
  401. //
  402. // Notes:
  403. //
  404. BOOL FEqualComponents(INetCfgComponent *pnccA, INetCfgComponent *pnccB)
  405. {
  406. GUID guidA;
  407. GUID guidB;
  408. if (SUCCEEDED(pnccA->GetInstanceGuid(&guidA)) &&
  409. SUCCEEDED(pnccB->GetInstanceGuid(&guidB)))
  410. {
  411. return (guidA == guidB);
  412. }
  413. return FALSE;
  414. }
  415. //
  416. // Debug functions
  417. //
  418. #ifdef ENABLETRACE
  419. //+---------------------------------------------------------------------------
  420. //
  421. // Function: DbgDumpBindPath
  422. //
  423. // Purpose: Dumps the given binding path in an easy to read format
  424. //
  425. // Arguments:
  426. // pncbp [in] Bind path to dump
  427. //
  428. // Returns: Nothing
  429. //
  430. // Author: danielwe 26 Nov 1997
  431. //
  432. // Notes:
  433. //
  434. VOID DbgDumpBindPath(INetCfgBindingPath *pncbp)
  435. {
  436. HRESULT hr = S_OK;
  437. tstring strPath;
  438. INetCfgBindingInterface * pncbi;
  439. INetCfgComponent * pncc = NULL;
  440. PWSTR pszwCompId;
  441. if ((!pncbp) || IsBadReadPtr((CONST VOID *)pncbp,
  442. sizeof(INetCfgBindingPath *)))
  443. {
  444. TraceTag(ttidAdvCfg, "Bind path is invalid!");
  445. return;
  446. }
  447. CIterNetCfgBindingInterface ncbiIter(pncbp);
  448. while (SUCCEEDED(hr) && S_OK == (hr = ncbiIter.HrNext(&pncbi)))
  449. {
  450. if (strPath.empty())
  451. {
  452. hr = pncbi->GetUpperComponent(&pncc);
  453. if (SUCCEEDED(hr))
  454. {
  455. hr = pncc->GetId(&pszwCompId);
  456. if (SUCCEEDED(hr))
  457. {
  458. strPath = pszwCompId;
  459. CoTaskMemFree(pszwCompId);
  460. }
  461. ReleaseObj(pncc);
  462. pncc = NULL;
  463. }
  464. }
  465. hr = pncbi->GetLowerComponent(&pncc);
  466. if (SUCCEEDED(hr))
  467. {
  468. hr = pncc->GetId(&pszwCompId);
  469. if (SUCCEEDED(hr))
  470. {
  471. strPath += L" -> ";
  472. strPath += pszwCompId;
  473. CoTaskMemFree(pszwCompId);
  474. }
  475. ReleaseObj(pncc);
  476. }
  477. ReleaseObj(pncbi);
  478. }
  479. if (SUCCEEDED(hr))
  480. {
  481. TraceTag(ttidAdvCfg, "Address = 0x%08lx, Path is '%S'",
  482. pncbp, strPath.c_str());
  483. }
  484. else
  485. {
  486. TraceTag(ttidAdvCfg, "Error dumping binding path.");
  487. }
  488. }
  489. VOID DbgDumpTreeViewItem(HWND hwndTV, HTREEITEM hti)
  490. {
  491. WCHAR szText[256];
  492. TV_ITEM tvi;
  493. if (hti)
  494. {
  495. tvi.hItem = hti;
  496. tvi.pszText = szText;
  497. tvi.cchTextMax = celems(szText);
  498. tvi.mask = TVIF_TEXT;
  499. TreeView_GetItem(hwndTV, &tvi);
  500. TraceTag(ttidAdvCfg, "TreeView item is %S.", szText);
  501. }
  502. else
  503. {
  504. TraceTag(ttidAdvCfg, "TreeView item is NULL");
  505. }
  506. }
  507. #endif //ENABLETRACE