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.

866 lines
25 KiB

  1. /*++
  2. Module Name:
  3. MmcAdmin.cpp
  4. Abstract:
  5. This module contains the implementation for CMmcDfsAdmin. This is an class
  6. for MMC display related calls for the static node(the DFS Admin root node)
  7. --*/
  8. #include "stdafx.h"
  9. #include "DfsGUI.h"
  10. #include "Utils.h" // For the LoadStringFromResource method
  11. #include "resource.h" // Contains the menu and toolbar command ids
  12. #include "MenuEnum.h" // Contains the menu command ids
  13. #include "MmcRoot.h" // CMmcDfsRoot class
  14. #include "MmcAdmin.h"
  15. #include "DfsEnums.h" // for common enums, typedefs, etc
  16. #include "DfsWiz.h" // For the wizard pages, CCreateDfsRootWizPage1, 2, ...
  17. #include "DfsNodes.h" // For Node GUIDs
  18. #include "DfsScope.h"
  19. #include "mroots.h"
  20. static const TCHAR s_szWhack[] = _T("\\");
  21. static const TCHAR s_szWhackWhack[] = _T("\\\\");
  22. CMmcDfsAdmin::CMmcDfsAdmin(CDfsSnapinScopeManager* pScopeManager)
  23. : m_hItemParent(NULL),
  24. m_bDirty(false),
  25. m_lpConsole(NULL)
  26. {
  27. dfsDebugOut((_T("CMmcDfsAdmin::CMmcDfsAdmin this=%p\n"), this));
  28. m_CLSIDNodeType = s_guidDfsAdminNodeType;
  29. m_bstrDNodeType = s_tchDfsAdminNodeType;
  30. m_pScopeManager = pScopeManager;
  31. }
  32. CMmcDfsAdmin::~CMmcDfsAdmin()
  33. {
  34. CleanScopeChildren();
  35. dfsDebugOut((_T("CMmcDfsAdmin::~CMmcDfsAdmin this=%p\n"), this));
  36. }
  37. STDMETHODIMP
  38. CMmcDfsAdmin::AddMenuItems(
  39. IN LPCONTEXTMENUCALLBACK i_lpContextMenuCallback,
  40. IN LPLONG i_lpInsertionAllowed
  41. )
  42. /*++
  43. Routine Description:
  44. This routine adds a context menu using the ContextMenuCallback provided.
  45. Arguments:
  46. lpContextMenuCallback - A callback(function pointer) that is used to add the menu items
  47. lpInsertionAllowed - Specifies what menus can be added and where they can be added.
  48. --*/
  49. {
  50. RETURN_INVALIDARG_IF_NULL(i_lpContextMenuCallback);
  51. enum
  52. {
  53. IDM_CONTEXTMENU_COMMAND_MAX = IDM_STATIC_MAX,
  54. IDM_CONTEXTMENU_COMMAND_MIN = IDM_STATIC_MIN
  55. };
  56. LONG lInsertionPoints [IDM_CONTEXTMENU_COMMAND_MAX - IDM_CONTEXTMENU_COMMAND_MIN + 1] = {
  57. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  58. CCM_INSERTIONPOINTID_PRIMARY_TOP
  59. };
  60. LPTSTR aszLanguageIndependentName[IDM_CONTEXTMENU_COMMAND_MAX - IDM_CONTEXTMENU_COMMAND_MIN + 1] =
  61. {
  62. _T("StaticTopNewDfsRoot"),
  63. _T("StaticTopConnectTo")
  64. };
  65. CComPtr<IContextMenuCallback2> spiCallback2;
  66. HRESULT hr = i_lpContextMenuCallback->QueryInterface(IID_IContextMenuCallback2, (void **)&spiCallback2);
  67. RETURN_IF_FAILED(hr);
  68. for (int iCommandID = IDM_CONTEXTMENU_COMMAND_MIN, iMenuResource = IDS_MENUS_STATIC_TOP_NEW_DFSROOT;
  69. iCommandID <= IDM_CONTEXTMENU_COMMAND_MAX;
  70. iCommandID++,iMenuResource++)
  71. {
  72. CComBSTR bstrMenuText;
  73. CComBSTR bstrStatusBarText;
  74. hr = GetMenuResourceStrings(iMenuResource, &bstrMenuText, NULL, &bstrStatusBarText);
  75. RETURN_IF_FAILED(hr);
  76. CONTEXTMENUITEM2 ContextMenuItem;
  77. ZeroMemory(&ContextMenuItem, sizeof(ContextMenuItem));
  78. ContextMenuItem.strName = bstrMenuText;
  79. ContextMenuItem.strStatusBarText = bstrStatusBarText;
  80. ContextMenuItem.lInsertionPointID = lInsertionPoints[iCommandID - IDM_CONTEXTMENU_COMMAND_MIN];
  81. ContextMenuItem.lCommandID = iCommandID;
  82. ContextMenuItem.strLanguageIndependentName = aszLanguageIndependentName[iCommandID - IDM_CONTEXTMENU_COMMAND_MIN];
  83. LONG lInsertionFlag = 0; // Use to check if we have permission to add this menu.
  84. switch(ContextMenuItem.lInsertionPointID)
  85. {
  86. case CCM_INSERTIONPOINTID_PRIMARY_TOP:
  87. lInsertionFlag = CCM_INSERTIONALLOWED_TOP;
  88. break;
  89. case CCM_INSERTIONPOINTID_PRIMARY_NEW:
  90. lInsertionFlag = CCM_INSERTIONALLOWED_NEW;
  91. break;
  92. case CCM_INSERTIONPOINTID_PRIMARY_TASK:
  93. lInsertionFlag = CCM_INSERTIONALLOWED_TASK;
  94. break;
  95. case CCM_INSERTIONPOINTID_PRIMARY_VIEW:
  96. lInsertionFlag = CCM_INSERTIONALLOWED_VIEW;
  97. break;
  98. default:
  99. break;
  100. }
  101. if (*i_lpInsertionAllowed & lInsertionFlag) // Add the menu item we have have the permission
  102. {
  103. hr = spiCallback2->AddItem(&ContextMenuItem);
  104. RETURN_IF_FAILED(hr);
  105. }
  106. } // for
  107. return hr;
  108. }
  109. STDMETHODIMP
  110. CMmcDfsAdmin::Command(
  111. IN LONG i_lCommandID
  112. )
  113. /*++
  114. Routine Description:
  115. Action to be taken on a context menu selection or click is takes place.
  116. Arguments:
  117. lCommandID - The Command ID of the menu for which action has to be taken
  118. --*/
  119. {
  120. HRESULT hr = S_OK;
  121. switch (i_lCommandID)
  122. {
  123. case IDM_STATIC_TOP_CONNECTTO:
  124. hr = OnConnectTo();
  125. break;
  126. case IDM_STATIC_TOP_NEW_DFSROOT:
  127. hr = OnNewDfsRoot();
  128. break;
  129. default:
  130. hr = E_INVALIDARG;
  131. break;
  132. }
  133. return hr;
  134. };
  135. STDMETHODIMP
  136. CMmcDfsAdmin::OnConnectTo(
  137. )
  138. /*++
  139. Routine Description:
  140. Action to be taken on menu command "Connect To Dfs Root"
  141. --*/
  142. {
  143. // Display the ConnectTo dialog
  144. CConnectToDialog ConnectTo; // Connect To Dialog.
  145. HRESULT hr = ConnectTo.DoModal();
  146. do
  147. {
  148. if (hr != S_OK) // Mostly an error or cancel operation
  149. return hr;
  150. // Get the Dfs Root selected by the user
  151. CComBSTR bstrUserEnteredText;
  152. hr = ConnectTo.get_DfsRoot(&bstrUserEnteredText);
  153. RETURN_IF_FAILED(hr);
  154. CWaitCursor WaitCursor;
  155. if (S_OK == CheckUNCPath(bstrUserEnteredText))
  156. {
  157. //
  158. // user has entered the fully spelled out root entry path
  159. // add it to scope pane directly
  160. //
  161. hr = AddDfsRoot(bstrUserEnteredText);
  162. } else
  163. {
  164. //
  165. // user has entered only a domain or server name, we need user to further
  166. // determine the roots he wants to display in the scope pane
  167. //
  168. PTSTR pszScopeWithNoWhacks = NULL;
  169. if (!mylstrncmpi(bstrUserEnteredText, _T("\\\\"), 2))
  170. {
  171. pszScopeWithNoWhacks = bstrUserEnteredText + 2;
  172. } else
  173. {
  174. pszScopeWithNoWhacks = bstrUserEnteredText;
  175. }
  176. ROOTINFOLIST DfsRootList;
  177. hr = GetMultiDfsRoots(&DfsRootList, pszScopeWithNoWhacks);
  178. if (S_OK == hr && !DfsRootList.empty())
  179. {
  180. ROOTINFOLIST::iterator i = DfsRootList.begin();
  181. if (1 == DfsRootList.size())
  182. {
  183. //
  184. // this domain or server only hosts one root, add it to scope pane directly
  185. //
  186. hr = AddDfsRoot((*i)->bstrRootName);
  187. } else
  188. {
  189. //
  190. // invoke the multi roots dialog
  191. //
  192. CMultiRoots mroots;
  193. hr = mroots.Init(pszScopeWithNoWhacks, &DfsRootList);
  194. if (SUCCEEDED(hr))
  195. hr = mroots.DoModal();
  196. if (S_OK == hr)
  197. {
  198. //
  199. // user has OK'ed the dialog, add each selected root to scope pane
  200. //
  201. NETNAMELIST *pList = NULL;
  202. mroots.get_SelectedRootList(&pList);
  203. for (NETNAMELIST::iterator j = pList->begin(); j != pList->end(); j++)
  204. {
  205. hr = AddDfsRoot((*j)->bstrNetName);
  206. if (FAILED(hr))
  207. break;
  208. }
  209. } else if (S_FALSE == hr)
  210. {
  211. //
  212. // user has cancelled the dialog, reset it to S_OK to avoid msg popup
  213. //
  214. hr = S_OK;
  215. }
  216. }
  217. } else if (S_FALSE != hr)
  218. {
  219. //
  220. // could be downlevel server, try to add it to scope pane
  221. //
  222. hr = AddDfsRoot(bstrUserEnteredText);
  223. }
  224. FreeRootInfoList(&DfsRootList);
  225. }
  226. if (S_OK == hr)
  227. break;
  228. if (S_FALSE == hr)
  229. DisplayMessageBoxWithOK(IDS_DFSROOT_NOT_EXIST, NULL);
  230. if (FAILED(hr))
  231. DisplayMessageBoxForHR(hr);
  232. hr = ConnectTo.DoModal();
  233. } while (TRUE);
  234. return hr;
  235. }
  236. STDMETHODIMP
  237. CMmcDfsAdmin::EnumerateScopePane(
  238. IN LPCONSOLENAMESPACE i_lpConsoleNameSpace,
  239. IN HSCOPEITEM i_hItemParent
  240. )
  241. /*++
  242. Routine Description:
  243. To eumerate(add) items in the scope pane. Dfs Roots in this case
  244. Arguments:
  245. i_lpConsoleNameSpace - The callback used to add items to the Scope pane
  246. i_hItemParent - HSCOPEITEM of the parent under which all the items will be added.
  247. --*/
  248. {
  249. RETURN_INVALIDARG_IF_NULL(i_hItemParent);
  250. RETURN_INVALIDARG_IF_NULL(i_lpConsoleNameSpace);
  251. m_hItemParent = i_hItemParent;
  252. m_lpConsoleNameSpace = i_lpConsoleNameSpace;
  253. CWaitCursor WaitCursor;
  254. for (DFS_ROOT_LIST::iterator i = m_RootList.begin(); i != m_RootList.end(); i++)
  255. {
  256. (void)((*i)->m_pMmcDfsRoot)->AddItemToScopePane(m_lpConsoleNameSpace, m_hItemParent);
  257. }
  258. return S_OK;
  259. }
  260. STDMETHODIMP
  261. CMmcDfsAdmin::AddDfsRoot(
  262. IN BSTR i_bstrDfsRootName
  263. )
  264. /*++
  265. Routine Description:
  266. Adds the DfsRoot to the internal list and to the Scope pane.
  267. Arguments:
  268. i_bstrDfsRootName - The full path(display name) of the DfsRoot to be created.
  269. Example, ComputerName\\DfsRootName or DomainName\DfsRootName
  270. --*/
  271. {
  272. RETURN_INVALIDARG_IF_NULL(i_bstrDfsRootName);
  273. CWaitCursor wait;
  274. // Create the IDfsRoot object
  275. CComPtr<IDfsRoot> pDfsRoot;
  276. HRESULT hr = CoCreateInstance (CLSID_DfsRoot, NULL, CLSCTX_INPROC_SERVER, IID_IDfsRoot, (void**) &pDfsRoot);
  277. RETURN_IF_FAILED(hr);
  278. hr = pDfsRoot->Initialize(i_bstrDfsRootName);
  279. if (S_OK != hr)
  280. return hr;
  281. // Get the server hosting Dfs.
  282. CComBSTR bstrDfsRootEntryPath;
  283. hr = pDfsRoot->get_RootEntryPath(&bstrDfsRootEntryPath);
  284. RETURN_IF_FAILED(hr);
  285. // If already present in the list, just display a message and return
  286. CMmcDfsRoot *pMmcDfsRoot = NULL;
  287. hr = IsAlreadyInList(bstrDfsRootEntryPath, &pMmcDfsRoot);
  288. if (S_OK == hr)
  289. {
  290. pMmcDfsRoot->OnRefresh(); // refresh to pick up other root replicas
  291. return hr;
  292. }
  293. // Add the IDfsRoot object to the list and to Scope Pane
  294. hr = AddDfsRootToList(pDfsRoot);
  295. m_bDirty = true; // Dirty is true as we now have a new node in the list
  296. return hr;
  297. }
  298. STDMETHODIMP
  299. CMmcDfsAdmin::AddDfsRootToList(
  300. IN IDfsRoot* i_pDfsRoot,
  301. IN ULONG i_ulLinkFilterMaxLimit, // = FILTERDFSLINKS_MAXLIMIT_DEFAULT,
  302. IN FILTERDFSLINKS_TYPE i_lLinkFilterType, // = FILTERDFSLINKS_TYPE_NO_FILTER,
  303. IN BSTR i_bstrLinkFilterName // = NULL
  304. )
  305. /*++
  306. Routine Description:
  307. To add a new DFSRoot only to the list.
  308. Arguments:
  309. i_pDfsRoot - The IDfsRoot object being added to the list
  310. --*/
  311. {
  312. RETURN_INVALIDARG_IF_NULL(i_pDfsRoot);
  313. CMmcDfsRoot* pMmcDfsRoot = new CMmcDfsRoot(i_pDfsRoot, this, m_lpConsole,
  314. i_ulLinkFilterMaxLimit, i_lLinkFilterType, i_bstrLinkFilterName);
  315. RETURN_OUTOFMEMORY_IF_NULL(pMmcDfsRoot);
  316. HRESULT hr = pMmcDfsRoot->m_hrValueFromCtor;
  317. if (FAILED(hr))
  318. {
  319. delete pMmcDfsRoot;
  320. return hr;
  321. }
  322. CComBSTR bstrRootEntryPath;
  323. hr = i_pDfsRoot->get_RootEntryPath(&bstrRootEntryPath);
  324. if (FAILED(hr))
  325. {
  326. delete pMmcDfsRoot;
  327. return hr;
  328. }
  329. // Create a new node for storing Dfs Root information.
  330. DFS_ROOT_NODE* pNewDfsRootNode = new DFS_ROOT_NODE(pMmcDfsRoot, bstrRootEntryPath);
  331. if (!pNewDfsRootNode || !pNewDfsRootNode->m_bstrRootEntryPath)
  332. {
  333. delete pMmcDfsRoot;
  334. delete pNewDfsRootNode;
  335. return E_OUTOFMEMORY;
  336. }
  337. m_RootList.push_back(pNewDfsRootNode);
  338. // Add this DfsRoot to scope pane. Need item parent to be non null
  339. if (m_hItemParent)
  340. {
  341. hr = (pNewDfsRootNode->m_pMmcDfsRoot)->AddItemToScopePane(m_lpConsoleNameSpace, m_hItemParent);
  342. RETURN_IF_FAILED(hr);
  343. }
  344. m_bDirty = true; // Dirty is true as we now have a new node in the list
  345. return hr;
  346. }
  347. // This method returns the pointer to the list containing information of all DfsRoots
  348. // added to the Snapin. The caller SHOULD NOT free the list.
  349. STDMETHODIMP
  350. CMmcDfsAdmin::GetList(
  351. OUT DFS_ROOT_LIST** o_pList
  352. )
  353. {
  354. RETURN_INVALIDARG_IF_NULL(o_pList);
  355. *o_pList = &m_RootList;
  356. return S_OK;
  357. }
  358. STDMETHODIMP
  359. CMmcDfsAdmin::IsAlreadyInList(
  360. IN BSTR i_bstrDfsRootEntryPath,
  361. OUT CMmcDfsRoot **o_ppMmcDfsRoot
  362. )
  363. /*++
  364. Routine Description:
  365. Routine used to check if the DfsRoot is already in the list
  366. Arguments:
  367. i_bstrDfsRootEntryPath - The Server name of the DfsRoot object
  368. Return value:
  369. S_OK, if node is present in the list.
  370. S_FALSE, if the node doesn't exist in the list
  371. --*/
  372. {
  373. for (DFS_ROOT_LIST::iterator i = m_RootList.begin(); i != m_RootList.end(); i++)
  374. {
  375. if (!lstrcmpi((*i)->m_bstrRootEntryPath, i_bstrDfsRootEntryPath))
  376. {
  377. if (o_ppMmcDfsRoot)
  378. *o_ppMmcDfsRoot = (*i)->m_pMmcDfsRoot;
  379. return S_OK;
  380. }
  381. }
  382. return S_FALSE;
  383. }
  384. HRESULT
  385. CMmcDfsAdmin::OnRefresh(
  386. )
  387. {
  388. // Select this node first
  389. m_lpConsole->SelectScopeItem(m_hItemParent);
  390. CWaitCursor WaitCursor;
  391. HRESULT hr = S_OK;
  392. NETNAMELIST listRootEntryPaths;
  393. if (!m_RootList.empty())
  394. {
  395. for (DFS_ROOT_LIST::iterator i = m_RootList.begin(); i != m_RootList.end(); i++)
  396. {
  397. // silently close all property pages
  398. ((*i)->m_pMmcDfsRoot)->CloseAllPropertySheets(TRUE);
  399. NETNAME *pName = new NETNAME;
  400. BREAK_OUTOFMEMORY_IF_NULL(pName, &hr);
  401. pName->bstrNetName = (*i)->m_bstrRootEntryPath;
  402. BREAK_OUTOFMEMORY_IF_NULL((BSTR)(pName->bstrNetName), &hr);
  403. listRootEntryPaths.push_back(pName);
  404. }
  405. }
  406. if (FAILED(hr))
  407. {
  408. FreeNetNameList(&listRootEntryPaths);
  409. return hr;
  410. }
  411. if (listRootEntryPaths.empty())
  412. return hr;
  413. CleanScopeChildren();
  414. for (NETNAMELIST::iterator i = listRootEntryPaths.begin(); i != listRootEntryPaths.end(); i++)
  415. {
  416. (void)AddDfsRoot((*i)->bstrNetName);
  417. }
  418. FreeNetNameList(&listRootEntryPaths);
  419. return hr;
  420. }
  421. // Delete the node from m_RootList
  422. STDMETHODIMP
  423. CMmcDfsAdmin::DeleteMmcRootNode(
  424. IN CMmcDfsRoot* i_pMmcDfsRoot
  425. )
  426. {
  427. RETURN_INVALIDARG_IF_NULL(i_pMmcDfsRoot);
  428. dfsDebugOut((_T("CMmcDfsAdmin::DeleteMmcRootNode %p\n"), i_pMmcDfsRoot));
  429. for (DFS_ROOT_LIST::iterator i = m_RootList.begin(); i != m_RootList.end(); i++)
  430. {
  431. if ((*i)->m_pMmcDfsRoot == i_pMmcDfsRoot)
  432. {
  433. m_RootList.erase(i);
  434. m_bDirty = true;
  435. break;
  436. }
  437. }
  438. return S_OK;
  439. }
  440. STDMETHODIMP
  441. CMmcDfsAdmin::SetConsoleVerbs(
  442. IN LPCONSOLEVERB i_lpConsoleVerb
  443. )
  444. /*++
  445. Routine Description:
  446. Routine used to set the console verb settings.
  447. Sets all of them except Open off.
  448. For all scope pane items, default verb is "open'. For result items,
  449. it is "properties"
  450. Arguments:
  451. i_lpConsoleVerb - The callback used to handle console verbs
  452. --*/
  453. {
  454. RETURN_INVALIDARG_IF_NULL(i_lpConsoleVerb);
  455. i_lpConsoleVerb->SetVerbState(MMC_VERB_COPY, HIDDEN, TRUE);
  456. i_lpConsoleVerb->SetVerbState(MMC_VERB_PASTE, HIDDEN, TRUE);
  457. i_lpConsoleVerb->SetVerbState(MMC_VERB_RENAME, HIDDEN, TRUE);
  458. i_lpConsoleVerb->SetVerbState(MMC_VERB_PRINT, HIDDEN, TRUE);
  459. i_lpConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, TRUE);
  460. i_lpConsoleVerb->SetVerbState(MMC_VERB_OPEN, HIDDEN, TRUE);
  461. i_lpConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  462. i_lpConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  463. i_lpConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN); //For scope items, default verb is "open"
  464. return S_OK;
  465. }
  466. STDMETHODIMP
  467. CMmcDfsAdmin::OnNewDfsRoot(
  468. )
  469. /*++
  470. Routine Description:
  471. Action to be taken on menu command "New Dfs Root".
  472. Here is a wizard is used to guide the user through the process of creating a new
  473. dfs root.
  474. Arguments:
  475. None
  476. --*/
  477. {
  478. //
  479. // Use MMC main window as the parent as our modal wizard
  480. //
  481. HWND hwndMainWin = 0;
  482. HRESULT hr = m_lpConsole->GetMainWindow(&hwndMainWin);
  483. RETURN_IF_FAILED(hr);
  484. CREATEDFSROOTWIZINFO CreateWizInfo;// 0 initializes all members to 0. Necessary
  485. CreateWizInfo.pMMCAdmin = this;
  486. CCreateDfsRootWizPage1 WizPage1(&CreateWizInfo); // Wizard pages
  487. CCreateDfsRootWizPage2 WizPage2(&CreateWizInfo);
  488. CCreateDfsRootWizPage3 WizPage3(&CreateWizInfo);
  489. CCreateDfsRootWizPage4 WizPage4(&CreateWizInfo);
  490. CCreateDfsRootWizPage6 WizPage6(&CreateWizInfo);
  491. CCreateDfsRootWizPage5 WizPage5(&CreateWizInfo);
  492. CCreateDfsRootWizPage7 WizPage7(&CreateWizInfo);
  493. CComPtr<IPropertySheetCallback> pPropSheetCallback;
  494. hr = m_lpConsole->QueryInterface(IID_IPropertySheetCallback, (void**)&pPropSheetCallback);
  495. RETURN_IF_FAILED(hr);
  496. CComPtr<IPropertySheetProvider> pPropSheetProvider;
  497. hr = m_lpConsole->QueryInterface(IID_IPropertySheetProvider, (void**)&pPropSheetProvider);
  498. RETURN_IF_FAILED(hr);
  499. hr = pPropSheetProvider->CreatePropertySheet(
  500. _T(""), // Property sheet title. Should not be null so send empty string.
  501. FALSE, // Wizard and not property sheet.
  502. 0, // Cookie
  503. NULL, // IDataobject
  504. MMC_PSO_NEWWIZARDTYPE); // Creation flags
  505. if (SUCCEEDED(hr))
  506. {
  507. pPropSheetCallback->AddPage(WizPage1.Create());
  508. pPropSheetCallback->AddPage(WizPage2.Create());
  509. pPropSheetCallback->AddPage(WizPage3.Create());
  510. pPropSheetCallback->AddPage(WizPage4.Create());
  511. pPropSheetCallback->AddPage(WizPage6.Create());
  512. pPropSheetCallback->AddPage(WizPage5.Create());
  513. pPropSheetCallback->AddPage(WizPage7.Create());
  514. hr = pPropSheetProvider->AddPrimaryPages(
  515. (IComponentData *)(m_pScopeManager),
  516. FALSE, // Don't create a notify handle
  517. NULL,
  518. TRUE // Scope pane (not result pane)
  519. );
  520. if (SUCCEEDED(hr))
  521. hr = pPropSheetProvider->Show(
  522. (LONG_PTR)hwndMainWin, // Parent window of the wizard
  523. 0 // Starting page
  524. );
  525. //
  526. // If failed, call IPropertySheetProvider::Show(-1,0) to
  527. // delete the property sheet and free its resources
  528. //
  529. if (FAILED(hr))
  530. pPropSheetProvider->Show(-1, 0);
  531. }
  532. RETURN_IF_FAILED(hr);
  533. if (CreateWizInfo.bDfsSetupSuccess)
  534. {
  535. CComBSTR bstrRootEntryPath = _T("\\\\");
  536. if (CreateWizInfo.DfsType == DFS_TYPE_FTDFS)
  537. bstrRootEntryPath += CreateWizInfo.bstrSelectedDomain;
  538. else
  539. bstrRootEntryPath += CreateWizInfo.bstrSelectedServer;
  540. bstrRootEntryPath += _T("\\");
  541. bstrRootEntryPath += CreateWizInfo.bstrDfsRootName;
  542. hr = AddDfsRoot(bstrRootEntryPath);
  543. }
  544. return hr;
  545. }
  546. HRESULT
  547. CMmcDfsAdmin::SetDescriptionBarText(
  548. IN LPRESULTDATA i_lpResultData
  549. )
  550. /*++
  551. Routine Description:
  552. A routine used set the text in the Description bar above
  553. the result view.
  554. Arguments:
  555. i_lpResultData - Pointer to the IResultData callback which is
  556. used to set the description text
  557. --*/
  558. {
  559. RETURN_INVALIDARG_IF_NULL(i_lpResultData);
  560. CComBSTR bstrTextForDescriptionBar;
  561. LoadStringFromResource(IDS_DESCRIPTION_BAR_TEXT_ADMIN, &bstrTextForDescriptionBar);
  562. i_lpResultData->SetDescBarText(bstrTextForDescriptionBar);
  563. return S_OK;
  564. }
  565. HRESULT
  566. CMmcDfsAdmin::ToolbarSelect(
  567. IN const LONG i_lArg,
  568. IN IToolbar* i_pToolBar
  569. )
  570. /*++
  571. Routine Description:
  572. Handle a select event for a toolbar
  573. Enable the buttons, if the event for a selection.
  574. Disable the buttons, if the event was for a deselection
  575. Arguments:
  576. i_lArg - The argument passed to the actual method.
  577. o_pToolBar - The Toolbar pointer.
  578. --*/
  579. {
  580. RETURN_INVALIDARG_IF_NULL(i_pToolBar);
  581. EnableToolbarButtons(i_pToolBar, IDT_ADMIN_MIN, IDT_ADMIN_MAX, (BOOL)HIWORD(i_lArg));
  582. return S_OK;
  583. }
  584. HRESULT
  585. CMmcDfsAdmin::CreateToolbar(
  586. IN const LPCONTROLBAR i_pControlbar,
  587. IN const LPEXTENDCONTROLBAR i_lExtendControlbar,
  588. OUT IToolbar** o_pToolBar
  589. )
  590. /*++
  591. Routine Description:
  592. Create the toolbar.
  593. Involves the actual toolbar creation call, creating the bitmap and adding it
  594. and finally adding the buttons to the toolbar
  595. Arguments:
  596. i_pControlbar - The controlbar used to create toolbar.
  597. i_lExtendControlbar - The object implementing IExtendControlbar. This is
  598. the class exposed to MMC.
  599. o_pToolBar - The Toolbar pointer.
  600. --*/
  601. {
  602. RETURN_INVALIDARG_IF_NULL(i_pControlbar);
  603. RETURN_INVALIDARG_IF_NULL(i_lExtendControlbar);
  604. RETURN_INVALIDARG_IF_NULL(o_pToolBar);
  605. // Create the toolbar
  606. HRESULT hr = i_pControlbar->Create(TOOLBAR, i_lExtendControlbar, reinterpret_cast<LPUNKNOWN*>(o_pToolBar));
  607. RETURN_IF_FAILED(hr);
  608. // Add the bitmap to the toolbar
  609. hr = AddBitmapToToolbar(*o_pToolBar, IDB_ADMIN_TOOLBAR);
  610. RETURN_IF_FAILED(hr);
  611. int iButtonPosition = 0; // The first button position
  612. for (int iCommandID = IDT_ADMIN_MIN, iMenuResource = IDS_MENUS_STATIC_TOP_NEW_DFSROOT;
  613. iCommandID <= IDT_ADMIN_MAX;
  614. iCommandID++,iMenuResource++,iButtonPosition++)
  615. {
  616. CComBSTR bstrMenuText;
  617. CComBSTR bstrToolTipText;
  618. hr = GetMenuResourceStrings(iMenuResource, &bstrMenuText, &bstrToolTipText, NULL);
  619. RETURN_IF_FAILED(hr);
  620. // Add all the buttons to the toolbar
  621. MMCBUTTON ToolbarButton;
  622. ZeroMemory(&ToolbarButton, sizeof ToolbarButton);
  623. ToolbarButton.nBitmap = iButtonPosition;
  624. ToolbarButton.idCommand = iCommandID;
  625. ToolbarButton.fsState = TBSTATE_ENABLED;
  626. ToolbarButton.fsType = TBSTYLE_BUTTON;
  627. ToolbarButton.lpButtonText = bstrMenuText;
  628. ToolbarButton.lpTooltipText = bstrToolTipText;
  629. // Add the button to the toolbar
  630. hr = (*o_pToolBar)->InsertButton(iButtonPosition, &ToolbarButton);
  631. RETURN_IF_FAILED(hr);
  632. }
  633. return hr;
  634. }
  635. STDMETHODIMP
  636. CMmcDfsAdmin::ToolbarClick(
  637. IN const LPCONTROLBAR i_pControlbar,
  638. IN const LPARAM i_lParam
  639. )
  640. /*++
  641. Routine Description:
  642. Action to take on a click on a toolbar
  643. Arguments:
  644. i_pControlbar - The controlbar used to create toolbar.
  645. i_lParam - The lparam to the actual notify. This is the command id of
  646. the button on which a click occurred.
  647. --*/
  648. {
  649. RETURN_INVALIDARG_IF_NULL(i_pControlbar);
  650. HRESULT hr = S_OK;
  651. switch(i_lParam) // What button did the user click on.
  652. {
  653. case IDT_ADMIN_CONNECTTO:
  654. hr = OnConnectTo();
  655. break;
  656. case IDT_ADMIN_NEW_DFSROOT:
  657. hr = OnNewDfsRoot();
  658. break;
  659. default:
  660. hr = E_INVALIDARG;
  661. break;
  662. };
  663. return hr;
  664. }
  665. STDMETHODIMP CMmcDfsAdmin::CleanScopeChildren(
  666. )
  667. {
  668. /*++
  669. Routine Description:
  670. Recursively deletes all Scope pane children display objects.
  671. --*/
  672. HRESULT hr = S_OK;
  673. if (!m_RootList.empty())
  674. {
  675. // clean up display objects
  676. for (DFS_ROOT_LIST::iterator i = m_RootList.begin(); i != m_RootList.end(); i++)
  677. {
  678. (*i)->m_pMmcDfsRoot->RemoveFromMMC();
  679. delete (*i);
  680. }
  681. m_RootList.erase(m_RootList.begin(), m_RootList.end());
  682. }
  683. return S_OK;
  684. }