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.

666 lines
17 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: samplesnap.cxx
  7. //
  8. // Contents: Classes that implement sample snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #include "stdafx.hxx"
  12. //+-------------------------------------------------------------------
  13. //
  14. // Member: CSnapinRootItem::ScInit
  15. //
  16. // Synopsis: Called immeadiately after the item is created to init
  17. // displayname, icon index etc...
  18. //
  19. // Arguments: [CBaseSnapin] -
  20. // [CColumnInfoEx] - Any columns to be displayed for this item.
  21. // [INT] - # of columns
  22. //
  23. // Returns: SC
  24. //
  25. //--------------------------------------------------------------------
  26. SC CSnapinRootItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  27. {
  28. DECLARE_SC(sc, _T("CSnapinRootItem::ScInit"));
  29. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  30. if (sc)
  31. return sc;
  32. // Init following
  33. // a. Icon index.
  34. // b. Load display name.
  35. m_uIconIndex = 3; // use an enum instead of 3
  36. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_SAMPLEROOT);
  37. return sc;
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: CSnapinRootItem::ScGetField
  42. //
  43. // Synopsis: Get the string representation for given field to display
  44. // it in result pane.
  45. //
  46. // Arguments: [DAT] - The column requested (this is an enumeration).
  47. // [tstring] - Out string.
  48. //
  49. // Returns: SC
  50. //
  51. //--------------------------------------------------------------------
  52. SC CSnapinRootItem::ScGetField (DAT dat, tstring& strField)
  53. {
  54. DECLARE_SC(sc, _T("CSnapinRootItem::ScGetField"));
  55. switch(dat)
  56. {
  57. case datString1:
  58. strField = _T("Root String1");
  59. break;
  60. case datString2:
  61. strField = _T("Root String2");
  62. break;
  63. case datString3:
  64. strField = _T("Root String3");
  65. break;
  66. default:
  67. E_INVALIDARG;
  68. break;
  69. }
  70. return (sc);
  71. }
  72. //+-------------------------------------------------------------------
  73. //
  74. // Member: CSnapinRootItem::ScCreateChildren
  75. //
  76. // Synopsis: Create any children (nodes & leaf items) for this item.
  77. //
  78. // Arguments: None
  79. //
  80. // Returns: SC
  81. //
  82. //--------------------------------------------------------------------
  83. SC CSnapinRootItem::ScCreateChildren ()
  84. {
  85. DECLARE_SC(sc, _T("CSnapinRootItem::ScCreateChildren"));
  86. t_itemChild * pitemChild = NULL;
  87. t_itemChild * pitemPrevious = NULL;
  88. // If creating multiple items pass "previous" parameter so that the items are linked in
  89. // the internal linked list which will be enumerated & inserted in scope/result pane.
  90. // See CBaseSnapinItem::ScCreateItem which will be called by ScCreateLVContainer.
  91. // Create the child nodes and init them.
  92. sc = CSampleSnapinLVContainer::ScCreateLVContainer(this, &pitemChild, FALSE); // Why FALSE???
  93. if (sc)
  94. return sc;
  95. pitemPrevious = pitemChild;
  96. // Next item to create... (If there is next item then it must be linked with previous item)
  97. // See comments above for more information.
  98. return (sc);
  99. }
  100. //+-------------------------------------------------------------------
  101. //
  102. // Member: CSampleSnapinLVContainer::ScInit
  103. //
  104. // Synopsis: Called immeadiately after the item is created to init
  105. // displayname, icon index etc...
  106. //
  107. // Arguments: [CBaseSnapin] -
  108. // [CColumnInfoEx] - Any columns to be displayed for this item.
  109. // [INT] - # of columns
  110. //
  111. // Returns: SC
  112. //
  113. //--------------------------------------------------------------------
  114. SC CSampleSnapinLVContainer::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  115. {
  116. DECLARE_SC(sc, _T("CSampleSnapinLVContainer::ScInit"));
  117. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  118. if (sc)
  119. return sc;
  120. // Init following
  121. // a. Icon index.
  122. // b. Load display name.
  123. m_uIconIndex = 4; // use an enum instead of 4
  124. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_LVContainer);
  125. return sc;
  126. }
  127. //+-------------------------------------------------------------------
  128. //
  129. // Member: CSampleSnapinLVContainer::ScGetField
  130. //
  131. // Synopsis: Get the string representation for given field to display
  132. // it in result pane.
  133. //
  134. // Arguments: [DAT] - The column requested (this is an enumeration).
  135. // [tstring] - Out string.
  136. //
  137. // Returns: SC
  138. //
  139. //--------------------------------------------------------------------
  140. SC CSampleSnapinLVContainer::ScGetField (DAT dat, tstring& strField)
  141. {
  142. DECLARE_SC(sc, _T("CSampleSnapinLVContainer::ScGetField"));
  143. switch(dat)
  144. {
  145. case datString1:
  146. strField = _T("LVContainer String1");
  147. break;
  148. case datString2:
  149. strField = _T("LVContainer String2");
  150. break;
  151. case datString3:
  152. strField = _T("LVContainer String3");
  153. break;
  154. default:
  155. E_INVALIDARG;
  156. break;
  157. }
  158. return (sc);
  159. }
  160. //+-------------------------------------------------------------------
  161. //
  162. // Member: CSampleSnapinLVContainer::ScCreateChildren
  163. //
  164. // Synopsis: Create any children (nodes & leaf items) for this item.
  165. //
  166. // Arguments: None
  167. //
  168. // Returns: SC
  169. //
  170. //--------------------------------------------------------------------
  171. SC CSampleSnapinLVContainer::ScCreateChildren ()
  172. {
  173. DECLARE_SC(sc, _T("CSampleSnapinLVContainer::ScCreateChildren"));
  174. t_itemChild * pitemChild = NULL;
  175. t_itemChild * pitemPrevious = NULL;
  176. // Let us create 10 items for this container.
  177. for (int i = 0; i < 10; ++i)
  178. {
  179. // Create the child nodes and init them.
  180. sc = CSampleSnapinLVLeafItem::ScCreateLVLeafItem(this, pitemPrevious, &pitemChild, FALSE); // Why FALSE???
  181. if (sc)
  182. return sc;
  183. pitemPrevious = pitemChild;
  184. }
  185. return (sc);
  186. }
  187. //+-------------------------------------------------------------------
  188. //
  189. // Member: CSampleSnapinLVContainer::ScCreateLVContainer
  190. //
  191. // Synopsis: Do we really need this method?
  192. //
  193. // Arguments:
  194. //
  195. // Returns: SC
  196. //
  197. //--------------------------------------------------------------------
  198. SC CSampleSnapinLVContainer::ScCreateLVContainer(CSnapinRootItem *pitemParent, t_item ** ppitem, BOOL fNew)
  199. {
  200. DECLARE_SC(sc, _T("CSnapinRootItem::ScCreateLVContainer"));
  201. t_item * pitem = NULL;
  202. *ppitem = NULL;
  203. // What to do here?
  204. sc = ::ScCreateItem(pitemParent, NULL, &pitem, fNew);
  205. if (sc)
  206. return sc;
  207. *ppitem = pitem;
  208. return (sc);
  209. }
  210. //+-------------------------------------------------------------------
  211. //
  212. // Member: CSampleSnapinLVLeafItem::ScInit
  213. //
  214. // Synopsis: Called immeadiately after the item is created to init
  215. // displayname, icon index etc...
  216. //
  217. // Arguments: [CBaseSnapin] -
  218. // [CColumnInfoEx] - Any columns to be displayed for this item.
  219. // [INT] - # of columns
  220. //
  221. // Returns: SC
  222. //
  223. //--------------------------------------------------------------------
  224. SC CSampleSnapinLVLeafItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  225. {
  226. DECLARE_SC(sc, _T("CSampleSnapinLVLeafItem::ScInit"));
  227. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  228. if (sc)
  229. return sc;
  230. // Init following
  231. // a. Icon index.
  232. // b. Load display name.
  233. m_uIconIndex = 7; // use an enum instead of 7
  234. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_LVLeafItem);
  235. return sc;
  236. }
  237. //+-------------------------------------------------------------------
  238. //
  239. // Member: CSampleSnapinLVLeafItem::ScGetField
  240. //
  241. // Synopsis: Get the string representation for given field to display
  242. // it in result pane.
  243. //
  244. // Arguments: [DAT] - The column requested (this is an enumeration).
  245. // [tstring] - Out string.
  246. //
  247. // Returns: SC
  248. //
  249. //--------------------------------------------------------------------
  250. SC CSampleSnapinLVLeafItem::ScGetField (DAT dat, tstring& strField)
  251. {
  252. DECLARE_SC(sc, _T("CSampleSnapinLVLeafItem::ScGetField"));
  253. switch(dat)
  254. {
  255. case datString1:
  256. strField = _T("LVLeaf String1");
  257. break;
  258. case datString2:
  259. strField = _T("LVLeaf String2");
  260. break;
  261. case datString3:
  262. strField = _T("LVLeaf String3");
  263. break;
  264. default:
  265. E_INVALIDARG;
  266. break;
  267. }
  268. return (sc);
  269. }
  270. //+-------------------------------------------------------------------
  271. //
  272. // Member: CSampleSnapinLVLeafItem::ScCreateLVLeafItem
  273. //
  274. // Synopsis: Do we really need this method?
  275. //
  276. // Arguments:
  277. //
  278. // Returns: SC
  279. //
  280. //--------------------------------------------------------------------
  281. SC CSampleSnapinLVLeafItem::ScCreateLVLeafItem(CSampleSnapinLVContainer *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew)
  282. {
  283. DECLARE_SC(sc, _T("CSampleSnapinLVLeafItem::ScCreateLVLeafItem"));
  284. t_itemChild * pitem = NULL;
  285. *ppitem = NULL;
  286. // What to do here?
  287. sc = ::ScCreateItem(pitemParent, pitemPrevious, &pitem, fNew);
  288. if (sc)
  289. return sc;
  290. *ppitem = pitem;
  291. return (sc);
  292. }
  293. // Initialize context menu structures. Let us have one item for demonstration.
  294. SnapinMenuItem CSampleSnapinLVLeafItem::s_rgmenuitemLVLeafItem[] =
  295. {
  296. {IDS_NewLVItem, IDS_NewLVItem, IDS_NewLVItem, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, dwMenuNeverChecked},
  297. };
  298. INT CSampleSnapinLVLeafItem::s_cmenuitemLVLeafItem = CMENUITEM(s_rgmenuitemLVLeafItem);
  299. // -----------------------------------------------------------------------------
  300. SnapinMenuItem *CSampleSnapinLVLeafItem::Pmenuitem(void)
  301. {
  302. return s_rgmenuitemLVLeafItem;
  303. }
  304. // -----------------------------------------------------------------------------
  305. INT CSampleSnapinLVLeafItem::CMenuItem(void)
  306. {
  307. return s_cmenuitemLVLeafItem;
  308. }
  309. //+-------------------------------------------------------------------
  310. //
  311. // Member: CSampleSnapinLVLeafItem::ScCommand
  312. //
  313. // Synopsis:
  314. //
  315. // Arguments:
  316. //
  317. // Returns: SC
  318. //
  319. //--------------------------------------------------------------------
  320. SC CSampleSnapinLVLeafItem::ScCommand (long nCommandID, CComponent *pComponent)
  321. {
  322. DECLARE_SC(sc, _T("CSampleSnapinLVLeafItem::ScCommand"));
  323. switch(nCommandID)
  324. {
  325. case IDS_NewLVItem:
  326. sc = ScInsertResultItem(pComponent);
  327. break;
  328. default:
  329. sc = E_INVALIDARG;
  330. break;
  331. }
  332. return (sc);
  333. }
  334. //-------------------------------------------------------------------------------------
  335. // class CSampleSnapin
  336. #pragma BEGIN_CODESPACE_DATA
  337. SNR CSampleSnapin::s_rgsnr[] =
  338. {
  339. SNR(&nodetypeSampleRoot, snrEnumSP ), // Standalone snapin.
  340. SNR(&nodetypeSampleLVContainer, snrEnumSP | snrEnumRP ), // enumerates this node in the scope pane and result pane.
  341. SNR(&nodetypeSampleLVLeafItem, snrEnumSP | snrEnumRP ), // enumerates this node in the scope pane and result pane.
  342. };
  343. LONG CSampleSnapin::s_rgiconid[] = {3};
  344. LONG CSampleSnapin::s_iconidStatic = 2;
  345. CColumnInfoEx CSampleSnapin::s_colinfo[] =
  346. {
  347. CColumnInfoEx(_T("Column Name0"), LVCFMT_LEFT, 180, datString1),
  348. CColumnInfoEx(_T("Column Name1"), LVCFMT_LEFT, 180, datString2),
  349. CColumnInfoEx(_T("Column Name2"), LVCFMT_LEFT, 180, datString3),
  350. };
  351. INT CSampleSnapin::s_ccolinfo = sizeof(s_colinfo) / sizeof(CColumnInfoEx);
  352. INT CSampleSnapin::s_colwidths[1];
  353. #pragma END_CODESPACE_DATA
  354. // include members needed for every snapin.
  355. SNAPIN_DEFINE( CSampleSnapin);
  356. /* CSampleSnapin::CSampleSnapin
  357. *
  358. * PURPOSE: Constructor
  359. *
  360. * PARAMETERS: None
  361. *
  362. */
  363. CSampleSnapin::CSampleSnapin()
  364. {
  365. m_pstrDisplayName = new tstring();
  366. *m_pstrDisplayName = _T("Sample Snapin Root");
  367. }
  368. /* CSampleSnapin::~CSampleSnapin
  369. *
  370. * PURPOSE: Destructor
  371. *
  372. * PARAMETERS: None
  373. *
  374. */
  375. CSampleSnapin::~CSampleSnapin()
  376. {
  377. delete m_pstrDisplayName;
  378. }
  379. //-------------------------------------------------------------------------------------
  380. // class CSampleGhostRootSnapinItem
  381. /* CSampleGhostRootSnapinItem::ScInitializeNamespaceExtension
  382. *
  383. * PURPOSE:
  384. *
  385. * PARAMETERS:
  386. * PDATAOBJECT lpDataObject:
  387. * HSCOPEITEM item:
  388. * CNodeType * pNodeType:
  389. *
  390. * RETURNS:
  391. * SC
  392. */
  393. SC
  394. CSampleGhostRootSnapinItem::ScInitializeNamespaceExtension(LPDATAOBJECT lpDataObject, HSCOPEITEM item, CNodeType *pNodeType)
  395. {
  396. DECLARE_SC(sc, _T("CSampleGhostRootSnapinItem::ScInitializeNamespaceExtension()"));
  397. return sc;
  398. }
  399. /* CSampleGhostRootSnapinItem::ScCreateChildren
  400. *
  401. * PURPOSE: Creates children items
  402. *
  403. * PARAMETERS:
  404. *
  405. * RETURNS:
  406. * SC
  407. */
  408. SC
  409. CSampleGhostRootSnapinItem::ScCreateChildren( void )
  410. {
  411. DECLARE_SC(sc, _T("CSampleGhostRootSnapinItem::ScCreateChildren()"));
  412. t_itemChild * pitemChild = NULL;
  413. sc = CBaseProtSnapinItem::ScCreateItem(this, NULL, &pitemChild, FALSE /*fNew*/ );
  414. if (sc)
  415. return sc;
  416. pitemChild->InitContainer();
  417. return sc;
  418. }
  419. //-------------------------------------------------------------------------------------
  420. // class CBaseProtSnapinItem
  421. /* CBaseProtSnapinItem::CBaseProtSnapinItem
  422. *
  423. * PURPOSE: Constructor
  424. *
  425. * PARAMETERS: None
  426. *
  427. */
  428. CBaseProtSnapinItem::CBaseProtSnapinItem()
  429. {
  430. m_fIsContainer = FALSE;
  431. }
  432. /* CBaseProtSnapinItem::ScGetField
  433. *
  434. * PURPOSE: Gets the string value of a field.
  435. *
  436. * PARAMETERS:
  437. * DAT dat: The field.
  438. * STR * pstrField: [OUT]: The string value.
  439. *
  440. * RETURNS:
  441. * SC
  442. */
  443. SC
  444. CBaseProtSnapinItem::ScGetField(DAT dat, tstring& strField)
  445. {
  446. ASSERT(FALSE);
  447. return S_OK;
  448. }
  449. /* CBaseProtSnapinItem::ScCreateChildren
  450. *
  451. * PURPOSE: Creates children items
  452. *
  453. * PARAMETERS:
  454. *
  455. * RETURNS:
  456. * SC
  457. */
  458. SC
  459. CBaseProtSnapinItem::ScCreateChildren( void )
  460. {
  461. DECLARE_SC(sc, _T("CBaseProtSnapinItem::ScCreateChildren()"));
  462. t_itemChild * pitemChild = NULL;
  463. t_itemChild * pitemPrevious = NULL;
  464. if ( FIsContainer() )
  465. {
  466. for ( INT idob = 0; idob < 10; idob++ )
  467. {
  468. // insert protocols
  469. sc = ScCreateItem(this, pitemPrevious, &pitemChild, FALSE /*fNew*/);
  470. if (sc)
  471. return sc;
  472. pitemPrevious = pitemChild;
  473. }
  474. }
  475. return sc;
  476. }
  477. /* CBaseProtSnapinItem::ScCreateItem
  478. *
  479. * PURPOSE: Creates a new child item, assuming the DOB for it already exists.
  480. *
  481. * PARAMETERS:
  482. * CBaseSnapinItem * pitemParent The parent of this item - should be 'this' of the calling class
  483. * t_itemChild * pitemPrevious: The previous item to link the newly created item to.
  484. * t_itemChild ** ppitem: [OUT]: The new item.
  485. * BOOL fNew new item?
  486. *
  487. * RETURNS:
  488. * SC
  489. */
  490. SC
  491. CBaseProtSnapinItem::ScCreateItem(CBaseSnapinItem *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew)
  492. {
  493. DECLARE_SC(sc, _T("CBaseProtSnapinItem::ScCreateItem()"));
  494. t_itemChild * pitem = NULL;
  495. *ppitem = NULL;
  496. sc = ::ScCreateItem(pitemParent, pitemPrevious, &pitem, fNew);
  497. if (sc)
  498. return sc;
  499. *ppitem = pitem;
  500. return sc;
  501. }
  502. //-------------------------------------------------------------------------------------
  503. // class CSampleExtnSnapin
  504. #pragma BEGIN_CODESPACE_DATA // $REVIEW should all the nodetypes be registered?
  505. SNR CSampleExtnSnapin::s_rgsnr[] =
  506. {
  507. // SNR(&nodetypeSampleRoot, snrExtNS ), // extends the namespace of a server node.
  508. SNR(&nodetypeSampleExtnNode, snrEnumSP | snrEnumRP ),// enumerates this node in the scope pane and result pane.
  509. };
  510. LONG CSampleExtnSnapin::s_rgiconid[] = { 0};
  511. LONG CSampleExtnSnapin::s_iconidStatic = 0;
  512. CColumnInfoEx CSampleExtnSnapin::s_colinfo[] =
  513. {
  514. CColumnInfoEx(_T("Extn Column Name0"), LVCFMT_LEFT, 180, datString1),
  515. };
  516. INT CSampleExtnSnapin::s_ccolinfo = sizeof(s_colinfo) / sizeof(CColumnInfoEx);
  517. INT CSampleExtnSnapin::s_colwidths[1];
  518. #pragma END_CODESPACE_DATA
  519. // include members needed for every snapin.
  520. SNAPIN_DEFINE(CSampleExtnSnapin);
  521. /* CSampleExtnSnapin::CSampleExtnSnapin
  522. *
  523. * PURPOSE: Constructor
  524. *
  525. * PARAMETERS: None
  526. *
  527. */
  528. CSampleExtnSnapin::CSampleExtnSnapin()
  529. {
  530. m_pstrDisplayName = new tstring();
  531. *m_pstrDisplayName = _T("Sample Snapin Extn");
  532. }
  533. /* CSampleExtnSnapin::~CSampleExtnSnapin
  534. *
  535. * PURPOSE: Destructor
  536. *
  537. * PARAMETERS: None
  538. *
  539. */
  540. CSampleExtnSnapin::~CSampleExtnSnapin()
  541. {
  542. delete m_pstrDisplayName;
  543. }