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.

364 lines
12 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright 1995 - 1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "Service.h"
  10. #include "CSnapin.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. // Primary Data
  17. RESULT_DATA StaticRootData[NUM_NAMES] =
  18. {
  19. {RESULT_ITEM, USER, L"Bill", L"990", L"CEO"},
  20. {RESULT_ITEM, USER, L"Jill", L"991", L"Director"},
  21. {RESULT_ITEM, USER, L"Hill", L"992", L"President"},
  22. {RESULT_ITEM, USER, L"Will", L"993", L"Chairman"},
  23. };
  24. RESULT_DATA UserData[NUM_NAMES] =
  25. {
  26. {RESULT_ITEM, USER, L"Joe", L"100", L"Employee"},
  27. {RESULT_ITEM, USER, L"Harry", L"101", L"Manager"},
  28. {RESULT_ITEM, USER, L"Jane", L"102", L"Vice President"},
  29. {RESULT_ITEM, USER, L"Sue", L"103", L"Developer"},
  30. };
  31. RESULT_DATA CompanyData[NUM_COMPANY] =
  32. {
  33. {RESULT_ITEM, COMPANY, L"Taxes", L"43", L"IRS Documents"},
  34. {RESULT_ITEM, COMPANY, L"Medical", L"345", L"HMO"},
  35. {RESULT_ITEM, COMPANY, L"Dental", L"121", L"Plus Plan"},
  36. {RESULT_ITEM, COMPANY, L"Insurance", L"2332", L"Dollars are Us"},
  37. {RESULT_ITEM, COMPANY, L"401K", L"1000", L"Up to you"},
  38. {RESULT_ITEM, COMPANY, L"Legal", L"78", L"Yes"}
  39. };
  40. // Extension data
  41. RESULT_DATA UserDataExt[NUM_NAMES] =
  42. {
  43. {RESULT_ITEM, EXT_USER, L"Charles", L"200", L"Employee"},
  44. {RESULT_ITEM, EXT_USER, L"Jill", L"201", L"Manager"},
  45. {RESULT_ITEM, EXT_USER, L"John", L"202", L"Vice President"},
  46. {RESULT_ITEM, EXT_USER, L"Tami", L"203", L"Developer"},
  47. };
  48. RESULT_DATA CompanyDataExt[NUM_COMPANY] =
  49. {
  50. {RESULT_ITEM, EXT_COMPANY, L"Payroll", L"99", L"Corporate Payroll"},
  51. {RESULT_ITEM, EXT_COMPANY, L"Health", L"568", L"HMO"},
  52. {RESULT_ITEM, EXT_COMPANY, L"Health Club", L"834", L"Plus Plan"},
  53. {RESULT_ITEM, EXT_COMPANY, L"Insurance", L"1101", L"Dollars are Us"},
  54. {RESULT_ITEM, EXT_COMPANY, L"401K", L"1543", L"Up to you"},
  55. {RESULT_ITEM, EXT_COMPANY, L"Legal", L"27", L"Yes"}
  56. };
  57. // We use a single structure for all virtual items, so
  58. // the name field points to this buffer that is changed
  59. // on the fly.
  60. WCHAR VirtualItemName[MAX_ITEM_NAME];
  61. RESULT_DATA VirtualData[1] =
  62. {
  63. {RESULT_ITEM, VIRTUAL, VirtualItemName, L"100", L"Virtual"}
  64. };
  65. /////////////////////////////////////////////////////////////////////////////
  66. // Event handlers for IFrame::Notify
  67. HRESULT CSnapin::OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  68. {
  69. ASSERT(FALSE);
  70. return S_OK;
  71. }
  72. HRESULT CSnapin::OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  73. {
  74. // if cookie is from a different snapin
  75. // if (IsMyCookie(cookie) == FALSE)
  76. if (arg)
  77. {
  78. // add the images for the scope tree only
  79. ::CBitmap bmp16x16;
  80. ::CBitmap bmp32x32;
  81. LPIMAGELIST lpImageList = reinterpret_cast<LPIMAGELIST>(arg);
  82. // Load the bitmaps from the dll
  83. bmp16x16.LoadBitmap(IDB_16x16);
  84. bmp32x32.LoadBitmap(IDB_32x32);
  85. // Set the images
  86. lpImageList->ImageListSetStrip(
  87. reinterpret_cast<PLONG_PTR>(static_cast<HBITMAP>(bmp16x16)),
  88. reinterpret_cast<PLONG_PTR>(static_cast<HBITMAP>(bmp32x32)),
  89. 0, RGB(255, 0, 255));
  90. }
  91. else
  92. {
  93. InitializeBitmaps(cookie);
  94. }
  95. return S_OK;
  96. }
  97. HRESULT CSnapin::OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  98. {
  99. // Note - arg is TRUE when it is time to enumerate
  100. if (arg == TRUE)
  101. {
  102. // if list view on display
  103. if (m_CustomViewID == VIEW_DEFAULT_LV)
  104. {
  105. // Show the headers for this nodetype
  106. InitializeHeaders(cookie);
  107. Enumerate(cookie, param);
  108. }
  109. else if (m_CustomViewID == VIEW_DEFAULT_MESSAGE_VIEW)
  110. {
  111. PopulateMessageView (cookie);
  112. }
  113. // BUBBUG - Demonstration to should how you can attach
  114. // and a toolbar when a particular nodes gets focus.
  115. // warning this needs to be here as the toolbars are
  116. // currently hidden when the previous node looses focus.
  117. // This should be update to show the user how to hide
  118. // and show toolbars. (Detach and Attach).
  119. //m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar1);
  120. //m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar2);
  121. }
  122. else
  123. {
  124. // BUGBUG - Demonstration this to show how to hide toolbars that
  125. // could be particular to a single node.
  126. // currently this is used to hide the toolbars the console
  127. // does not do any toolbar clean up.
  128. //m_pControlbar->Detach(m_pToolbar1);
  129. //m_pControlbar->Detach(m_pToolbar2);
  130. // Free data associated with the result pane items, because
  131. // your node is no longer being displayed.
  132. // Note: The console will remove the items from the result pane
  133. }
  134. return S_OK;
  135. }
  136. HRESULT CSnapin::OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  137. {
  138. return S_OK;
  139. }
  140. HRESULT CSnapin::OnResultItemClk(DATA_OBJECT_TYPES type, MMC_COOKIE cookie)
  141. {
  142. RESULT_DATA* pResult;
  143. if (m_bVirtualView == TRUE)
  144. {
  145. pResult = GetVirtualResultItem(cookie);
  146. }
  147. else if (cookie != 0)
  148. {
  149. DWORD* pdw = reinterpret_cast<DWORD*>(cookie);
  150. if (*pdw == RESULT_ITEM)
  151. {
  152. pResult = reinterpret_cast<RESULT_DATA*>(cookie);
  153. }
  154. }
  155. return S_OK;
  156. }
  157. HRESULT CSnapin::OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  158. {
  159. return S_OK;
  160. }
  161. HRESULT CSnapin::OnPropertyChange(LPDATAOBJECT lpDataObject)
  162. {
  163. return S_OK;
  164. }
  165. HRESULT CSnapin::OnUpdateView(LPDATAOBJECT lpDataObject)
  166. {
  167. return S_OK;
  168. }
  169. void CSnapin::Enumerate(MMC_COOKIE cookie, HSCOPEITEM pParent)
  170. {
  171. EnumerateResultPane(cookie);
  172. }
  173. void CSnapin::EnumerateResultPane(MMC_COOKIE cookie)
  174. {
  175. ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
  176. ASSERT(m_pComponentData != NULL);
  177. // Our static folders must be displayed in the result pane
  178. // by use because the console doesn't do it.
  179. CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie);
  180. FOLDER_TYPES type = pFolder ? pFolder->GetType() : STATIC;
  181. switch(type)
  182. {
  183. case STATIC:
  184. AddResultItems(&StaticRootData[0], NUM_NAMES, 4);
  185. break;
  186. case COMPANY:
  187. AddCompany();
  188. break;
  189. case USER:
  190. AddUser();
  191. break;
  192. case EXT_USER:
  193. AddExtUser();
  194. break;
  195. case EXT_COMPANY:
  196. AddExtCompany();
  197. break;
  198. case VIRTUAL:
  199. case EXT_VIRTUAL:
  200. AddVirtual();
  201. break;
  202. default:
  203. break;
  204. }
  205. }
  206. void CSnapin::PopulateMessageView(MMC_COOKIE cookie)
  207. {
  208. ASSERT(m_pComponentData != NULL);
  209. CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie);
  210. FOLDER_TYPES type = pFolder ? pFolder->GetType() : STATIC;
  211. IUnknown* pResultUnk;
  212. HRESULT hr = m_pConsole->QueryResultView (&pResultUnk);
  213. ASSERT (SUCCEEDED (hr) && "IConsole::QueryResultView failed");
  214. IMessageView* pMessageView;
  215. hr = pResultUnk->QueryInterface (IID_IMessageView, (void**) &pMessageView);
  216. ASSERT (SUCCEEDED (hr) && "Couldn't query IMessageView interface from the result pane.");
  217. switch(type)
  218. {
  219. case STATIC:
  220. pMessageView->SetTitleText (L"This is the Files node. It uses the error icon.");
  221. pMessageView->SetBodyText (L"REDMOND, Wash�Microsoft Corp. today will release a third test version of its Windows 2000 operating system to its plants, a major hurdle in delivering the long-delayed program to the market."
  222. L"\n\nThe third \"beta\" version of the program is expected to be the final test version before the product is completed. Shortly after the test code reaches Microsoft's manufacturing plants, the company is expected to begin the process of distributing as many as 650,000 copies, the widest reach yet of any test version of Windows. Many of those users will be paying for the privilege; Microsoft intends to charge $59.95 for copies of the Windows 2000 beta sold via its World Wide Web site.");
  223. pMessageView->SetIcon (Icon_Error);
  224. break;
  225. case COMPANY:
  226. pMessageView->SetTitleText (L"This is the Company node. It uses the information icon and has a really, really long title that should span several lines. In fact, it could span more than several lines, it could span dozens or even hundreds of lines.");
  227. pMessageView->SetBodyText (L"This is the (short) body text for the company node");
  228. pMessageView->SetIcon (Icon_Information);
  229. break;
  230. case USER:
  231. pMessageView->SetTitleText (L"This is the User node. Is uses the warning icon and has no body text.");
  232. pMessageView->SetBodyText (NULL);
  233. pMessageView->SetIcon (Icon_Warning);
  234. break;
  235. case VIRTUAL:
  236. case EXT_VIRTUAL:
  237. pMessageView->SetTitleText (L"This is the Virtual node. It has no icon.");
  238. pMessageView->SetBodyText (L"REDMOND, Wash�Microsoft Corp. today will release a third test version of its Windows 2000 operating system to its plants, a major hurdle in delivering the long-delayed program to the market."
  239. L"\n\nThe third \"beta\" version of the program is expected to be the final test version before the product is completed. Shortly after the test code reaches Microsoft's manufacturing plants, the company is expected to begin the process of distributing as many as 650,000 copies, the widest reach yet of any test version of Windows. Many of those users will be paying for the privilege; Microsoft intends to charge $59.95 for copies of the Windows 2000 beta sold via its World Wide Web site.");
  240. pMessageView->SetIcon (Icon_None);
  241. break;
  242. default:
  243. AfxMessageBox (_T("CSnapin::PopulateMessageView: default node type, clearing message view"));
  244. pMessageView->Clear ();
  245. break;
  246. }
  247. pMessageView->Release();
  248. pResultUnk->Release();
  249. }
  250. void CSnapin::AddResultItems(RESULT_DATA* pData, int nCount, int imageIndex)
  251. {
  252. ASSERT(m_pResult);
  253. RESULTDATAITEM resultItem;
  254. memset(&resultItem, 0, sizeof(RESULTDATAITEM));
  255. for (int i=0; i < nCount; i++)
  256. {
  257. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  258. resultItem.str = MMC_TEXTCALLBACK;
  259. resultItem.nImage = imageIndex;
  260. resultItem.lParam = reinterpret_cast<LPARAM>(pData + i);
  261. m_pResult->InsertItem(&resultItem);
  262. }
  263. m_pResult->Sort(0,0,-1);
  264. }
  265. void CSnapin::AddUser()
  266. {
  267. AddResultItems(&UserData[0], NUM_NAMES, 4);
  268. }
  269. void CSnapin::AddCompany()
  270. {
  271. AddResultItems(&CompanyData[0], NUM_COMPANY, 3);
  272. }
  273. void CSnapin::AddExtUser()
  274. {
  275. AddResultItems(&UserDataExt[0], NUM_NAMES, 4);
  276. }
  277. void CSnapin::AddExtCompany()
  278. {
  279. AddResultItems(&CompanyDataExt[0], NUM_COMPANY, 3);
  280. }
  281. void CSnapin::AddVirtual()
  282. {
  283. // for virtual data, just set the item count
  284. m_pResult->SetItemCount(NUM_VIRTUAL_ITEMS, MMCLV_UPDATE_NOINVALIDATEALL);
  285. }
  286. RESULT_DATA* CSnapin::GetVirtualResultItem(int iIndex)
  287. {
  288. // reverse order for descending sort
  289. if (m_dwVirtualSortOptions & RSI_DESCENDING)
  290. iIndex = (NUM_VIRTUAL_ITEMS - 1) - iIndex;
  291. // Create a name from the index
  292. swprintf(VirtualItemName, L"%d", iIndex);
  293. // return pointer to the virtual result item
  294. return &VirtualData[0];
  295. }