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.

419 lines
11 KiB

  1. // AllSystemsScopeItem.cpp: implementation of the CAllSystemsScopeItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "AllSystemsScopeItem.h"
  7. #include "AllSystemsResultsView.h"
  8. #include "HealthmonScopePane.h"
  9. #include "SystemScopeItem.h"
  10. #include "NewSystemDlg.h"
  11. #include "SelectSystemsDlg.h"
  12. #include "SystemGroup.h"
  13. #include "System.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[]=__FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19. IMPLEMENT_DYNCREATE(CAllSystemsScopeItem,CHMScopeItem)
  20. // {AB5EA8C7-B6D5-11d2-BD73-0000F87A3912}
  21. static GUID GUID_AllSystems =
  22. { 0xab5ea8c7, 0xb6d5, 0x11d2, { 0xbd, 0x73, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  23. // icon table - associates state to icons
  24. static UINT _Icons[HMS_MAX_STATES] =
  25. {
  26. IDI_ICON_SYSTEMS,
  27. IDI_ICON_SYSTEMS_DISABLED,
  28. IDI_ICON_SYSTEMS_OUTAGE,
  29. IDI_ICON_SYSTEMS_UNKNOWN,
  30. IDI_ICON_SYSTEMS_NO_CONNECT,
  31. IDI_ICON_SYSTEMS_WARNING,
  32. IDI_ICON_SYSTEMS_CRITICAL
  33. };
  34. //////////////////////////////////////////////////////////////////////
  35. // Construction/Destruction
  36. //////////////////////////////////////////////////////////////////////
  37. CAllSystemsScopeItem::CAllSystemsScopeItem()
  38. {
  39. m_lpguidItemType = &GUID_AllSystems;
  40. }
  41. CAllSystemsScopeItem::~CAllSystemsScopeItem()
  42. {
  43. Destroy();
  44. }
  45. //////////////////////////////////////////////////////////////////////
  46. // Creation Members
  47. //////////////////////////////////////////////////////////////////////
  48. bool CAllSystemsScopeItem::Create(CScopePane* pScopePane, CScopePaneItem* pParentItem)
  49. {
  50. TRACEX(_T("CAllSystemsScopeItem::Create\n"));
  51. TRACEARGn(pScopePane);
  52. TRACEARGn(pParentItem);
  53. // set up all the icons first
  54. for( int i = 0; i < HMS_MAX_STATES; i++ )
  55. {
  56. UINT nId = _Icons[i];
  57. m_IconResIds.Add(nId);
  58. m_OpenIconResIds.Add(nId);
  59. }
  60. SetIconIndex(HMS_NORMAL);
  61. SetOpenIconIndex(HMS_NORMAL);
  62. // call base class Create method
  63. if( ! CHMScopeItem::Create(pScopePane,pParentItem) )
  64. {
  65. TRACE(_T("CHMScopeItem::Create failed.\n"));
  66. return false;
  67. }
  68. // set display names
  69. CString sName;
  70. sName.LoadString(IDS_STRING_ALL_SYSTEMS_NODE);
  71. SetDisplayName(0,sName);
  72. return true;
  73. }
  74. //////////////////////////////////////////////////////////////////////
  75. // Results Pane View Members
  76. //////////////////////////////////////////////////////////////////////
  77. CResultsPaneView* CAllSystemsScopeItem::CreateResultsPaneView()
  78. {
  79. TRACEX(_T("CAllSystemsScopeItem::CreateResultsPaneView\n"));
  80. return new CAllSystemsResultsView;
  81. }
  82. //////////////////////////////////////////////////////////////////////
  83. // MMC Notify Handlers
  84. //////////////////////////////////////////////////////////////////////
  85. HRESULT CAllSystemsScopeItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  86. {
  87. TRACEX(_T("CAllSystemsScopeItem::OnAddMenuItems\n"));
  88. TRACEARGn(piCallback);
  89. TRACEARGn(pInsertionAllowed);
  90. HRESULT hr = S_OK;
  91. if( CCM_INSERTIONALLOWED_TOP & *pInsertionAllowed )
  92. {
  93. CONTEXTMENUITEM cmi;
  94. CString sResString;
  95. CString sResString2;
  96. sResString.LoadString(IDS_STRING_NEW_SYSTEM);
  97. cmi.strName = LPTSTR(LPCTSTR(sResString));
  98. sResString2.LoadString(IDS_STRING_NEW_SYSTEM_DESCRIPTION);
  99. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  100. cmi.lCommandID = IDM_NEW_SYSTEM;
  101. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  102. cmi.fFlags = 0;
  103. cmi.fSpecialFlags = 0;
  104. hr = piCallback->AddItem(&cmi);
  105. if( !SUCCEEDED(hr) )
  106. {
  107. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  108. return hr;
  109. }
  110. }
  111. // Add New Menu Items
  112. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  113. {
  114. }
  115. // Add Task Menu Items
  116. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  117. {
  118. CONTEXTMENUITEM cmi;
  119. CString sResString;
  120. CString sResString2;
  121. sResString.LoadString(IDS_STRING_CLEAR_EVENTS);
  122. cmi.strName = LPTSTR(LPCTSTR(sResString));
  123. sResString2.LoadString(IDS_STRING_CLEAR_EVENTS_DESCRIPTION);
  124. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  125. cmi.lCommandID = IDM_CLEAR_EVENTS;
  126. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  127. cmi.fFlags = 0;
  128. cmi.fSpecialFlags = 0;
  129. hr = piCallback->AddItem(&cmi);
  130. if( !SUCCEEDED(hr) )
  131. {
  132. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  133. return hr;
  134. }
  135. sResString.LoadString(IDS_STRING_RESET_STATUS);
  136. cmi.strName = LPTSTR(LPCTSTR(sResString));
  137. sResString2.LoadString(IDS_STRING_RESET_STATUS_DESCRIPTION);
  138. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  139. cmi.lCommandID = IDM_RESET_STATUS;
  140. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  141. cmi.fFlags = 0;
  142. cmi.fSpecialFlags = 0;
  143. hr = piCallback->AddItem(&cmi);
  144. if( !SUCCEEDED(hr) )
  145. {
  146. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  147. return hr;
  148. }
  149. // separator
  150. cmi.strName = NULL;
  151. cmi.strStatusBarText = NULL;
  152. cmi.lCommandID = NULL;
  153. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  154. cmi.fFlags = MF_SEPARATOR;
  155. cmi.fSpecialFlags = 0;
  156. hr = piCallback->AddItem(&cmi);
  157. if( !SUCCEEDED(hr) )
  158. {
  159. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  160. return hr;
  161. }
  162. }
  163. // Add View Menu Items
  164. if( CCM_INSERTIONALLOWED_VIEW & *pInsertionAllowed )
  165. {
  166. CONTEXTMENUITEM cmi;
  167. CString sResString;
  168. CString sResString2;
  169. sResString.LoadString(IDS_STRING_STATUS_ONLY);
  170. cmi.strName = LPTSTR(LPCTSTR(sResString));
  171. sResString2.LoadString(IDS_STRING_STATUS_ONLY_DESCRIPTION);
  172. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  173. cmi.lCommandID = IDM_STATUS_ONLY;
  174. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  175. cmi.fFlags = MF_UNCHECKED;
  176. cmi.fSpecialFlags = 0;
  177. hr = piCallback->AddItem(&cmi);
  178. if( !SUCCEEDED(hr) )
  179. {
  180. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  181. return hr;
  182. }
  183. sResString.LoadString(IDS_STRING_AUTO_FILTER);
  184. cmi.strName = LPTSTR(LPCTSTR(sResString));
  185. sResString2.LoadString(IDS_STRING_AUTO_FILTER_DESCRIPTION);
  186. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  187. cmi.lCommandID = IDM_AUTO_FILTER;
  188. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  189. cmi.fFlags = MF_CHECKED;
  190. cmi.fSpecialFlags = 0;
  191. hr = piCallback->AddItem(&cmi);
  192. if( !SUCCEEDED(hr) )
  193. {
  194. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  195. return hr;
  196. }
  197. // icon legend
  198. sResString.LoadString(IDS_STRING_ICON_LEGEND);
  199. cmi.strName = LPTSTR(LPCTSTR(sResString));
  200. sResString2.LoadString(IDS_STRING_ICON_LEGEND_DESCRIPTION);
  201. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  202. cmi.lCommandID = IDM_ICON_LEGEND;
  203. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  204. cmi.fFlags = 0;
  205. cmi.fSpecialFlags = 0;
  206. hr = piCallback->AddItem(&cmi);
  207. if( !SUCCEEDED(hr) )
  208. {
  209. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  210. return hr;
  211. }
  212. }
  213. return hr;
  214. }
  215. HRESULT CAllSystemsScopeItem::OnCommand(long lCommandID)
  216. {
  217. TRACEX(_T("CAllSystemsScopeItem::OnCommand\n"));
  218. TRACEARGn(lCommandID);
  219. HRESULT hr = S_OK;
  220. switch(lCommandID)
  221. {
  222. case IDM_NEW_SYSTEM:
  223. {
  224. CHealthmonScopePane* pPane = (CHealthmonScopePane*)GetScopePane();
  225. if( ! GfxCheckObjPtr(pPane,CHealthmonScopePane) )
  226. {
  227. TRACE(_T("FAILED : CGroupScopeItem::GetScopePane returns an invalid pointer.\n"));
  228. return E_FAIL;
  229. }
  230. /*
  231. CNewSystemDlg dlg;
  232. if( dlg.DoModal() == IDOK )
  233. {
  234. CSystemGroup* pMSG = pPane->GetRootGroup();
  235. CHMObject* pASG = ((CHMObject*)pMSG)->GetChild(0);
  236. if( pASG->GetChild(dlg.m_sName) )
  237. {
  238. return S_OK;
  239. }
  240. CSystem* pNewSystem = new CSystem;
  241. pNewSystem->SetName(dlg.m_sName);
  242. pNewSystem->SetSystemName(dlg.m_sName);
  243. pNewSystem->SetScopePane(pPane);
  244. pASG->AddChild(pNewSystem);
  245. pNewSystem->Connect();
  246. }
  247. */
  248. CSelectSystemsDlg dlg;
  249. if( dlg.DoModal() == IDOK )
  250. {
  251. CSystemGroup* pMSG = pPane->GetRootGroup();
  252. CHMObject* pASG = ((CHMObject*)pMSG)->GetChild(0);
  253. for( int i = 0; i < dlg.m_saSystems.GetSize(); i++ )
  254. {
  255. if( ! pASG->GetChild(dlg.m_saSystems[i]) )
  256. {
  257. IWbemServices* pServices = NULL;
  258. BOOL bAvail = FALSE;
  259. if( CnxGetConnection(dlg.m_saSystems[i],pServices,bAvail) == E_FAIL )
  260. {
  261. MessageBeep(MB_ICONEXCLAMATION);
  262. }
  263. if( pServices )
  264. {
  265. pServices->Release();
  266. }
  267. CSystem* pNewSystem = new CSystem;
  268. pNewSystem->SetName(dlg.m_saSystems[i]);
  269. pNewSystem->SetSystemName(dlg.m_saSystems[i]);
  270. pNewSystem->SetScopePane(pPane);
  271. pASG->AddChild(pNewSystem);
  272. pNewSystem->Connect();
  273. CActionPolicy* pPolicy = new CActionPolicy;
  274. pPolicy->SetSystemName(pNewSystem->GetName());
  275. pNewSystem->AddChild(pPolicy);
  276. }
  277. }
  278. }
  279. }
  280. break;
  281. default:
  282. {
  283. hr = CHMScopeItem::OnCommand(lCommandID);
  284. }
  285. }
  286. return hr;
  287. }
  288. HRESULT CAllSystemsScopeItem::OnExpand(BOOL bExpand)
  289. {
  290. TRACEX(_T("CAllSystemsScopeItem::OnExpand\n"));
  291. TRACEARGn(bExpand);
  292. CHMObject* pASG = GetObjectPtr();
  293. CString sLocalHost;
  294. DWORD dwLen = MAX_COMPUTERNAME_LENGTH;
  295. BOOL bResult = GetComputerName(sLocalHost.GetBuffer(MAX_COMPUTERNAME_LENGTH + 1),&dwLen);
  296. sLocalHost.ReleaseBuffer();
  297. if( pASG->GetChildCount() == 0 && bResult )
  298. {
  299. IWbemServices* pServices = NULL;
  300. BOOL bAvail = FALSE;
  301. if( CnxGetConnection(sLocalHost,pServices,bAvail) == E_FAIL )
  302. {
  303. MessageBeep(MB_ICONEXCLAMATION);
  304. }
  305. if( pServices )
  306. {
  307. pServices->Release();
  308. }
  309. CSystem* pNewSystem = new CSystem;
  310. pNewSystem->SetName(sLocalHost);
  311. pNewSystem->SetSystemName(sLocalHost);
  312. pNewSystem->SetScopePane(GetScopePane());
  313. pASG->AddChild(pNewSystem);
  314. pNewSystem->Connect();
  315. CActionPolicy* pPolicy = new CActionPolicy;
  316. pPolicy->SetSystemName(pNewSystem->GetName());
  317. pNewSystem->AddChild(pPolicy);
  318. }
  319. return CScopePaneItem::OnExpand(bExpand);
  320. }
  321. HRESULT CAllSystemsScopeItem::OnSelect(CResultsPane* pPane, BOOL bSelected)
  322. {
  323. TRACEX(_T("CAllSystemsScopeItem::OnSelect\n"));
  324. TRACEARGn(pPane);
  325. TRACEARGn(bSelected);
  326. static BOOL bSelectedOnce;
  327. CHMObject* pASG = GetObjectPtr();
  328. CString sLocalHost;
  329. DWORD dwLen = MAX_COMPUTERNAME_LENGTH;
  330. BOOL bResult = GetComputerName(sLocalHost.GetBuffer(MAX_COMPUTERNAME_LENGTH + 1),&dwLen);
  331. sLocalHost.ReleaseBuffer();
  332. if( bSelected && !bSelectedOnce && pASG->GetChildCount() == 1 && bResult )
  333. {
  334. if( pASG->GetChild(0)->GetSystemName().CompareNoCase(sLocalHost) == 0 )
  335. {
  336. for( int i = 0; i < pASG->GetChild(0)->GetScopeItemCount(); i++ )
  337. {
  338. pASG->GetChild(0)->GetScopeItem(i)->ExpandItem();
  339. bSelectedOnce = TRUE;
  340. }
  341. ExpandItem();
  342. }
  343. }
  344. return CScopePaneItem::OnSelect(pPane,bSelected);
  345. }