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.

304 lines
10 KiB

  1. // CompData.h : ComponentData Implementation classes.
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. #pragma once
  5. #define MSINFO_COMPDATA_H
  6. #include "StdAfx.h"
  7. #include <atlcom.h>
  8. #ifndef IDS_DESCRIPTION
  9. #include "Resource.h"
  10. #endif // IDS_DESCRIPTION
  11. // This hack is required because we may be building in an environment
  12. // which doesn't have a late enough version of rpcndr.h
  13. #if __RPCNDR_H_VERSION__ < 440
  14. #define __RPCNDR_H_VERSION__ 440
  15. #define MIDL_INTERFACE(x) interface
  16. #endif
  17. #ifndef __mmc_h__
  18. #include <mmc.h> // ..\..\..\public\sdk\inc
  19. #endif // __mmc_h__
  20. #include "DataObj.h"
  21. #include "DataSrc.h"
  22. #include "ScopeMap.h"
  23. #include "SysInfo.h"
  24. #include "chooser.h"
  25. #include "Dialogs.h"
  26. #ifndef IDS_SNAPIN_DESC
  27. #define IDS_SNAPIN_DESC IDS_DESCRIPTION
  28. #endif // IDS_SNAPIN_DESC
  29. #ifndef IDS_EXTENSION_DESC
  30. #define IDS_EXTENSION_DESC IDS_DESCRIPTION
  31. #endif // IDS_EXTENSION_DESC
  32. /*
  33. * CSystemInfoScope - the class interface to the Microsoft Management
  34. * Console namespace items of the MSInfo Snap-in.
  35. */
  36. class CSystemInfoScope:
  37. public IComponentData,
  38. public IExtendContextMenu,
  39. public IExtendPropertySheet,
  40. public IPersistStream,
  41. public ISnapinHelp,
  42. public CComObjectRoot
  43. {
  44. BEGIN_COM_MAP(CSystemInfoScope)
  45. COM_INTERFACE_ENTRY(IComponentData)
  46. COM_INTERFACE_ENTRY(IExtendContextMenu)
  47. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  48. COM_INTERFACE_ENTRY(IPersistStream)
  49. COM_INTERFACE_ENTRY(ISnapinHelp)
  50. END_COM_MAP()
  51. friend class CDataObject;
  52. friend class CCabTool;
  53. friend HRESULT CSystemInfo::OnDoubleClick(LPDATAOBJECT);
  54. friend HRESULT CSystemInfo::OnRefresh(LPDATAOBJECT);
  55. friend STDMETHODIMP CSystemInfo::GetDisplayInfo(LPRESULTDATAITEM);
  56. friend STDMETHODIMP CSystemInfo::Notify(LPDATAOBJECT pDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  57. friend void CSystemInfo::SetInitialVerbState(BOOL);
  58. friend HRESULT CSystemInfo::OnPropertyChange(LPDATAOBJECT);
  59. friend void CSystemInfo::SetRefreshing(LPARAM lparamMessage);
  60. // Constructors and destructors.
  61. public:
  62. CSystemInfoScope();
  63. ~CSystemInfoScope();
  64. public:
  65. virtual const CLSID &GetCoClassID() = 0;
  66. virtual const BOOL IsPrimaryImpl() = 0;
  67. // IComponentData interface members
  68. public:
  69. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  70. STDMETHOD(CreateComponent)(LPCOMPONENT *ppComponent);
  71. STDMETHOD(Destroy)();
  72. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  73. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT *ppDataObject);
  74. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM *pScopeDataItem);
  75. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  76. // IExtendContextMenu interface members
  77. public:
  78. STDMETHOD(AddMenuItems)(LPDATAOBJECT lpDataObject, LPCONTEXTMENUCALLBACK pCallback,
  79. long *pInsertionAllowed);
  80. STDMETHOD(Command)(long lCommandID, LPDATAOBJECT lpDataObject);
  81. // IExtendPropertySheet interface members
  82. public:
  83. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle,
  84. LPDATAOBJECT lpDataObject);
  85. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  86. // IPersistStream interface members
  87. public:
  88. STDMETHOD(GetClassID)(CLSID *pClassID);
  89. STDMETHOD(IsDirty)();
  90. STDMETHOD(Load)(IStream *pReadStream);
  91. STDMETHOD(Save)(IStream *pWriteStream, BOOL fClearDirty = TRUE);
  92. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  93. // ISnapinHelp interface member
  94. public:
  95. STDMETHOD(GetHelpTopic)(LPOLESTR __RPC_FAR *lpCompiledHelpFile);
  96. public:
  97. void SaveReport();
  98. void SaveFile();
  99. void PrintReport();
  100. void DoFind();
  101. void OpenFile();
  102. void CloseFile();
  103. void SetSelectedFolder(CFolder *pFolder);
  104. BOOL SelectItem(const CString &szPath, int iLine = 0);
  105. void SetView(enum DataComplexity, BOOL fViewInitialized = TRUE);
  106. MMC_COOKIE RootCookie() { return m_RootCookie; }
  107. void WaitForRefresh();
  108. BOOL InRefresh();
  109. void RefreshAsync(CFolder * pFolder, CSystemInfo * pSystemInfo, BOOL fSoftRefresh = TRUE);
  110. // Persistance debug instance variables
  111. private:
  112. bool m_bInitializedCD;
  113. #ifdef _DEBUG
  114. bool m_bLoadedCD;
  115. bool m_bDestroyedCD;
  116. #endif // _DEBUG
  117. public:
  118. enum CommandID { IDM_SAVEREPORT, IDM_SAVEFILE, IDM_FIND, IDM_PRINT, IDM_TASK_OPENFILE, IDM_TASK_CLOSE,
  119. IDM_TASK_FIND, IDM_TASK_SAVEREPORT, IDM_TASK_SAVEFILE, IDM_TASK_PRINT, IDM_TASK_VIEWCAB, IDM_VIEW_ADVANCED, IDM_VIEW_BASIC };
  120. // Private helper functions
  121. private:
  122. // AddToTopMenu is a convenience wrapper for AddToMenu
  123. HRESULT AddToTopMenu(LPCONTEXTMENUCALLBACK lpCallback, long lNameResource, long lStatusResource, long lCommandID)
  124. {
  125. return AddToMenu(lpCallback, lNameResource, lStatusResource, lCommandID,
  126. CCM_INSERTIONPOINTID_PRIMARY_TOP, 0L);
  127. }
  128. // AddToTaskMenu is a convenience wrapper for AddToMenu
  129. HRESULT AddToTaskMenu(LPCONTEXTMENUCALLBACK lpCallback, long lNameResource,
  130. long lStatusResource, long lCommandID)
  131. {
  132. return AddToMenu(lpCallback, lNameResource, lStatusResource, lCommandID,
  133. CCM_INSERTIONPOINTID_PRIMARY_TASK, 0L);
  134. }
  135. // AddToViewMenu is a convenience wrapper for AddToMenu
  136. HRESULT AddToViewMenu(LPCONTEXTMENUCALLBACK lpCallback, long lNameResource,
  137. long lStatusResource, long lCommandID, long fFlags)
  138. {
  139. return AddToMenu(lpCallback, lNameResource, lStatusResource, lCommandID,
  140. CCM_INSERTIONPOINTID_PRIMARY_VIEW, fFlags);
  141. }
  142. HRESULT AddToMenu(LPCONTEXTMENUCALLBACK lpCallback, long lNameResource,
  143. long lStatusResource, long lCommandID, long lInsertionPoint, long fFlags);
  144. HRESULT AddToolbarButtons(LPTOOLBAR pToolbar);
  145. HRESULT RefreshNameSpace();
  146. HRESULT AddSubMenu(CMenu *pMenu, void *pContext);
  147. HRESULT AddRoot(HSCOPEITEM hsiRoot, CFolder **ppFolder);
  148. HRESULT AddExtensionRoot(HSCOPEITEM &hsiNode, CFolder **ppFolder);
  149. HRESULT ScopeEnumerate(HSCOPEITEM hsiNode, CFolder *pFolder);
  150. HRESULT InitializeDialogs();
  151. HRESULT InitializeInternal();
  152. void DestroyInternal();
  153. HRESULT ProcessCommandLine();
  154. HRESULT MessageBox( CString lpszText);
  155. // We can't initialize in the Initialize function, so the real initialization
  156. // happens here.
  157. HRESULT InitializeSource();
  158. HRESULT InitializeView();
  159. BOOL SetMachine(const CString &strMachine);
  160. HRESULT PreUIInit();
  161. void PostUIInit();
  162. // Member access function
  163. public:
  164. CFolder *pRootCategory() const { return pSource() ? pSource()->GetRootNode() : NULL; }
  165. void CloseFindWindow();
  166. void ExecuteFind(long lFindState);
  167. void Refresh(CFolder *pfSelected = NULL, CSystemInfo * pSystemInfo = NULL);
  168. void StopFind();
  169. LPCTSTR MachineName() const;
  170. void DisplayGatherError(DWORD dwError, LPCTSTR szMachineName = NULL);
  171. // Member access functions.
  172. private:
  173. LPCONSOLENAMESPACE pScope() const { return m_pScope; }
  174. LPCONSOLE pConsole() const { return m_pConsole; }
  175. CDataSource *pSource() const { return m_pSource; }
  176. void SetSource(CDataSource *pNewSource, BOOL fPreLaunch = FALSE);
  177. // Notify handler declarations
  178. private:
  179. // We will probably never implement these methods.
  180. HRESULT OnRemoveChildren(long arg);
  181. HRESULT OnExpand(LPDATAOBJECT lpDataObject, LPARAM fExpand, HSCOPEITEM hsiNode);
  182. HRESULT OnProperties(LPARAM param);
  183. // Member access functions
  184. private:
  185. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  186. void ClearDirty() { SetDirty(FALSE); }
  187. BOOL ObjectIsDirty() { return m_bIsDirty; }
  188. // Internal data.
  189. private:
  190. LPCONSOLENAMESPACE m_pScope;
  191. LPCONSOLE m_pConsole;
  192. BOOL m_fViewUninitialized;
  193. CDataSource *m_pSource;
  194. CMSInfoReportDialog *m_prdReport;
  195. CMSInfoSaveDialog *m_prdSave;
  196. CMSInfoOpenDialog *m_prdOpen;
  197. long m_BasicFlags;
  198. long m_AdvancedFlags;
  199. CWnd *m_pwConsole;
  200. CFindThread *m_pthdFind;
  201. HWND m_hwndFind;
  202. MMC_COOKIE m_RootCookie;
  203. CFolder *m_pfLast;
  204. CString *m_pstrCategory;
  205. BOOL m_fSelectCategory;
  206. CString m_strDeferredLoad;
  207. CString m_strDeferredCategories;
  208. CString m_strDeferredMachine;
  209. BOOL m_fInternalDelete;
  210. // Save a pointer to the last system info object created - this can be used
  211. // to update that status bar when a global refresh is happening.
  212. CSystemInfo * m_pLastSystemInfo;
  213. // As a work around for the problem we're having when compmgmt redirects us,
  214. // we need a variable to save the IUnknown pointer to the console. When we
  215. // get an MMCN_REMOVE_CHILDREN notification, we will set this variable, then
  216. // uninitialize as if we were being unloaded. The next time we get an
  217. // MMCN_EXPAND message, we'll reinitialize as if we were starting up.
  218. LPUNKNOWN m_pSaveUnknown;
  219. // These variables are used to avoid calling SetSource twice on
  220. // initialization with the same parameters.
  221. CDataSource * m_pSetSourceSource;
  222. BOOL m_fSetSourcePreLaunch;
  223. // Memory leak problems associated with no call to CSystemInfoScope
  224. // destructor require these to be pointers.
  225. CString *m_pstrMachineName;
  226. CString *m_pstrOverrideName;
  227. CString m_strLastMachineName; // in case the new one is bad
  228. private:
  229. // Memory lead problems (see above)
  230. CScopeItemMap *m_pmapCategories;
  231. BOOL m_bIsDirty;
  232. CCabTool *m_pViewCABTool; // tool for viewing CAB contents
  233. };
  234. /*
  235. * CComponentDataPrimaryImpl - The subclass of the main user interface used as
  236. * the stand-alone portion of MSInfo.
  237. */
  238. class CSystemInfoScopePrimary : public CSystemInfoScope,
  239. public CComCoClass<CSystemInfoScopePrimary, &CLSID_MSInfo>
  240. {
  241. public:
  242. CSystemInfoScopePrimary() { }
  243. ~CSystemInfoScopePrimary() { }
  244. DECLARE_REGISTRY(CSnapin, _T("MSInfo.Snapin.1"), _T("MSInfo.Snapin"), IDS_SNAPIN_DESC, THREADFLAGS_APARTMENT)
  245. virtual const CLSID &GetCoClassID() { return CLSID_MSInfo; }
  246. virtual const BOOL IsPrimaryImpl() { return TRUE; }
  247. };
  248. /*
  249. * CComponentDataExtensionImpl - The subclass of the main user interface used as
  250. * the extension portion of MSInfo.
  251. */
  252. class CSystemInfoScopeExtension : public CSystemInfoScope,
  253. public CComCoClass<CSystemInfoScopeExtension, &CLSID_Extension>
  254. {
  255. public:
  256. CSystemInfoScopeExtension() { }
  257. ~CSystemInfoScopeExtension() { }
  258. DECLARE_REGISTRY(CSnapin, _T("MSInfo.Extension.1"), _T("MSInfo.Extension"), IDS_EXTENSION_DESC, THREADFLAGS_APARTMENT)
  259. virtual const CLSID &GetCoClassID() { return CLSID_Extension; }
  260. virtual const BOOL IsPrimaryImpl() { return FALSE; }
  261. };