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.

229 lines
5.8 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #ifndef __CMSNAPIN_H_
  3. #define __CMSNAPIN_H_
  4. #include "resource.h"
  5. #ifndef ATLASSERT
  6. #define ATLASSERT(expr) _ASSERTE(expr)
  7. #endif
  8. #include <atlsnap.h>
  9. #include "..\common\ServiceThread.h"
  10. class CCMSnapinExtData : public CSnapInItemImpl<CCMSnapinExtData, TRUE>
  11. {
  12. public:
  13. static const GUID* m_NODETYPE;
  14. static const OLECHAR* m_SZNODETYPE;
  15. static const OLECHAR* m_SZDISPLAY_NAME;
  16. static const CLSID* m_SNAPIN_CLASSID;
  17. CCMSnapinExtData()
  18. {
  19. memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
  20. memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));
  21. }
  22. ~CCMSnapinExtData()
  23. {
  24. }
  25. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  26. LONG_PTR handle,
  27. IUnknown* pUnk,
  28. DATA_OBJECT_TYPES type);
  29. STDMETHOD(QueryPagesFor)(DATA_OBJECT_TYPES type)
  30. {
  31. if (type == CCT_SCOPE || type == CCT_RESULT)
  32. return S_OK;
  33. return S_FALSE;
  34. }
  35. IDataObject* m_pDataObject;
  36. virtual void InitDataClass(IDataObject* pDataObject, CSnapInItem* pDefault)
  37. {
  38. m_pDataObject = pDataObject;
  39. // The default code stores off the pointer to the Dataobject the class is wrapping
  40. // at the time.
  41. // Alternatively you could convert the dataobject to the internal format
  42. // it represents and store that information
  43. }
  44. CSnapInItem* GetExtNodeObject(IDataObject* pDataObject, CSnapInItem* pDefault)
  45. {
  46. // Modify to return a different CSnapInItem* pointer.
  47. return pDefault;
  48. }
  49. };
  50. class CCMSnapin : public CComObjectRootEx<CComSingleThreadModel>,
  51. public CSnapInObjectRoot<0, CCMSnapin>,
  52. public IExtendPropertySheetImpl<CCMSnapin>,
  53. public CComCoClass<CCMSnapin, &CLSID_CMSnapin>,
  54. public ISnapinHelp
  55. {
  56. public:
  57. CCMSnapin()
  58. {
  59. m_pComponentData = this;
  60. }
  61. EXTENSION_SNAPIN_DATACLASS(CCMSnapinExtData)
  62. BEGIN_EXTENSION_SNAPIN_NODEINFO_MAP(CCMSnapin)
  63. EXTENSION_SNAPIN_NODEINFO_ENTRY(CCMSnapinExtData)
  64. END_EXTENSION_SNAPIN_NODEINFO_MAP()
  65. BEGIN_COM_MAP(CCMSnapin)
  66. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  67. COM_INTERFACE_ENTRY(ISnapinHelp)
  68. END_COM_MAP()
  69. //DECLARE_REGISTRY_RESOURCEID(IDR_CMSNAPIN)
  70. DECLARE_NOT_AGGREGATABLE(CCMSnapin)
  71. static HRESULT WINAPI UpdateRegistry(BOOL bRegister)
  72. {
  73. HRESULT hr;
  74. TCHAR pName[100] = {0};
  75. if(::LoadString(_Module.GetModuleInstance(), IDS_DISPLAY_NAME,
  76. pName, 100) <= 0)
  77. {
  78. wcscpy(pName, _T("System Properties"));
  79. }
  80. TCHAR dispName[100] = {0};
  81. TCHAR szModule[_MAX_PATH+1];
  82. szModule[_MAX_PATH] = 0;
  83. ::GetModuleFileName(_Module.GetModuleInstance(), szModule, _MAX_PATH);
  84. _stprintf( dispName,_T("@%s,-%d"), szModule, IDS_DISPLAY_NAME);
  85. _ATL_REGMAP_ENTRY regMap[] = {{ OLESTR("PRETTYNAME"), pName },
  86. { OLESTR("NAMESTRINGINDIRECT"),dispName},
  87. { 0, 0 }};
  88. hr = _Module.UpdateRegistryFromResourceD(IDR_CMSNAPIN, TRUE, regMap);
  89. return hr;
  90. }
  91. static void WINAPI ObjectMain(bool bStarting)
  92. {
  93. if (bStarting)
  94. CSnapInItem::Init();
  95. }
  96. STDMETHOD(GetHelpTopic)(LPOLESTR *lpCompiledHelpFile)
  97. {
  98. if(lpCompiledHelpFile == NULL)
  99. return E_POINTER;
  100. wchar_t helpDir[_MAX_PATH];
  101. memset(helpDir, 0, _MAX_PATH);
  102. if(GetWindowsDirectory(helpDir, _MAX_PATH) != 0)
  103. {
  104. wcscat(helpDir, L"\\Help");
  105. wcscat(helpDir, L"\\sysprop.chm");
  106. *lpCompiledHelpFile = reinterpret_cast<LPOLESTR>(
  107. CoTaskMemAlloc((wcslen(helpDir) + 1) *
  108. sizeof(wchar_t)));
  109. if(*lpCompiledHelpFile == NULL)
  110. return E_OUTOFMEMORY;
  111. USES_CONVERSION;
  112. wcscpy(*lpCompiledHelpFile, T2OLE((LPTSTR)(LPCTSTR)helpDir));
  113. return S_OK;
  114. }
  115. return E_UNEXPECTED;
  116. }
  117. };
  118. class ATL_NO_VTABLE CCMSnapinAbout : public ISnapinAbout,
  119. public CComObjectRoot,
  120. public CComCoClass< CCMSnapinAbout, &CLSID_CMSnapinAbout>
  121. {
  122. public:
  123. DECLARE_REGISTRY(CCMSnapinAbout, _T("CMSnapinAbout.1"), _T("CMSnapinAbout.1"), IDS_CMSNAPIN_DESC, THREADFLAGS_BOTH);
  124. BEGIN_COM_MAP(CCMSnapinAbout)
  125. COM_INTERFACE_ENTRY(ISnapinAbout)
  126. END_COM_MAP()
  127. STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
  128. {
  129. USES_CONVERSION;
  130. TCHAR szBuf[256];
  131. if (::LoadString(_Module.GetResourceInstance(), IDS_DESCRIPTION, szBuf, 256) == 0)
  132. return E_FAIL;
  133. *lpDescription = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  134. if (*lpDescription == NULL)
  135. return E_OUTOFMEMORY;
  136. ocscpy(*lpDescription, T2OLE(szBuf));
  137. return S_OK;
  138. }
  139. STDMETHOD(GetProvider)(LPOLESTR *lpName)
  140. {
  141. USES_CONVERSION;
  142. TCHAR szBuf[256];
  143. if (::LoadString(_Module.GetResourceInstance(), IDS_CMSNAPIN_PROVIDER, szBuf, 256) == 0)
  144. return E_FAIL;
  145. *lpName = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  146. if (*lpName == NULL)
  147. return E_OUTOFMEMORY;
  148. ocscpy(*lpName, T2OLE(szBuf));
  149. return S_OK;
  150. }
  151. STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
  152. {
  153. USES_CONVERSION;
  154. TCHAR szBuf[256];
  155. if (::LoadString(_Module.GetResourceInstance(), IDS_CMSNAPIN_VERSION, szBuf, 256) == 0)
  156. return E_FAIL;
  157. *lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  158. if (*lpVersion == NULL)
  159. return E_OUTOFMEMORY;
  160. ocscpy(*lpVersion, T2OLE(szBuf));
  161. return S_OK;
  162. }
  163. STDMETHOD(GetSnapinImage)(HICON *hAppIcon)
  164. {
  165. *hAppIcon = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_COMPUTER));
  166. return S_OK;
  167. }
  168. STDMETHOD(GetStaticFolderImage)(HBITMAP *hSmallImage,
  169. HBITMAP *hSmallImageOpen,
  170. HBITMAP *hLargeImage,
  171. COLORREF *cMask)
  172. {
  173. *hSmallImage = *hSmallImageOpen = LoadBitmap(_Module.GetResourceInstance(),
  174. MAKEINTRESOURCE(IDB_CMSNAPIN_16));
  175. *hLargeImage = LoadBitmap(_Module.GetResourceInstance(),
  176. MAKEINTRESOURCE(IDB_CMSNAPIN_32));
  177. *cMask = RGB(255,255,255);
  178. return S_OK;
  179. }
  180. };
  181. #endif