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.

320 lines
6.7 KiB

  1. /*++
  2. Module Name:
  3. DfsScope.cpp
  4. Abstract:
  5. This module contains the implementation for CDfsSnapinScopeManager.
  6. Most of the method of the class CDfsSnapinScopeManager are in other files.
  7. Only the constructor is here
  8. --*/
  9. #include "stdafx.h"
  10. #include "DfsGUI.h"
  11. #include "DfsScope.h"
  12. #include "MmcAdmin.h"
  13. #include "utils.h"
  14. CDfsSnapinScopeManager::CDfsSnapinScopeManager(
  15. )
  16. {
  17. m_hLargeBitmap = NULL;
  18. m_hSmallBitmap = NULL;
  19. m_hSmallBitmapOpen = NULL;
  20. m_hSnapinIcon = NULL;
  21. m_pMmcDfsAdmin = new CMmcDfsAdmin( this );
  22. }
  23. CDfsSnapinScopeManager::~CDfsSnapinScopeManager(
  24. )
  25. {
  26. m_pMmcDfsAdmin->Release();
  27. if (m_hLargeBitmap)
  28. {
  29. DeleteObject(m_hLargeBitmap);
  30. m_hLargeBitmap = NULL;
  31. }
  32. if (m_hSmallBitmap)
  33. {
  34. DeleteObject(m_hSmallBitmap);
  35. m_hSmallBitmap = NULL;
  36. }
  37. if (m_hSmallBitmapOpen)
  38. {
  39. DeleteObject(m_hSmallBitmapOpen);
  40. m_hSmallBitmapOpen = NULL;
  41. }
  42. if (m_hSnapinIcon)
  43. {
  44. DestroyIcon(m_hSnapinIcon);
  45. m_hSnapinIcon = NULL;
  46. }
  47. }
  48. #ifndef ARRAYSIZE
  49. #define ARRAYSIZE(x) sizeof(x)/sizeof(x[0])
  50. #endif
  51. typedef struct _RGSMAP {
  52. LPCTSTR szKey;
  53. UINT idString;
  54. } RGSMAP;
  55. RGSMAP g_aRgsSnapinRegs[] = {
  56. OLESTR("DfsAppName"), IDS_APPLICATION_NAME,
  57. OLESTR("DfsAppProvider"), IDS_SNAPINABOUT_PROVIDER,
  58. OLESTR("DfsAppVersion"), IDS_SNAPINABOUT_VERSION
  59. };
  60. HRESULT
  61. CDfsSnapinScopeManager::UpdateRegistry(BOOL bRegister)
  62. {
  63. HRESULT hr = S_OK;
  64. struct _ATL_REGMAP_ENTRY *pMapEntries = NULL;
  65. int n = ARRAYSIZE(g_aRgsSnapinRegs);
  66. int i = 0;
  67. if (n > 0)
  68. {
  69. // allocate 1 extra entry that is set to {NULL, NULL}
  70. pMapEntries = (struct _ATL_REGMAP_ENTRY *)calloc(n+1, sizeof(struct _ATL_REGMAP_ENTRY));
  71. if (!pMapEntries)
  72. return E_OUTOFMEMORY;
  73. CComBSTR bstrString;
  74. for (i=0; i<n; i++)
  75. {
  76. pMapEntries[i].szKey = g_aRgsSnapinRegs[i].szKey;
  77. hr = LoadStringFromResource(g_aRgsSnapinRegs[i].idString, &bstrString);
  78. if (FAILED(hr))
  79. break;
  80. pMapEntries[i].szData = T2OLE(bstrString.Detach());
  81. }
  82. }
  83. if (SUCCEEDED(hr))
  84. hr = _Module.UpdateRegistryFromResource(IDR_DFSSNAPINSCOPEMANAGER, bRegister, pMapEntries);
  85. // free resource strings
  86. if (n > 0)
  87. {
  88. for (i=0; i<n; i++)
  89. {
  90. if (pMapEntries[i].szData)
  91. SysFreeString( const_cast<LPTSTR>(OLE2CT(pMapEntries[i].szData)) );
  92. }
  93. free(pMapEntries);
  94. }
  95. return hr;
  96. }
  97. STDMETHODIMP CDfsSnapinScopeManager::CreatePropertyPages(
  98. IN LPPROPERTYSHEETCALLBACK i_lpPropSheetCallback,
  99. IN LONG_PTR i_lhandle,
  100. IN LPDATAOBJECT i_lpIDataObject
  101. )
  102. /*++
  103. Routine Description:
  104. Called to create PropertyPages for the given node.
  105. The fact that this has been called implies the display object has a
  106. page to display.
  107. Arguments:
  108. i_lpPropSheetCallback - The callback used to add pages.
  109. i_lhandle - The handle used for notification
  110. i_lpDataObject - The IDataObject pointer which is used to get
  111. the DisplayObject.
  112. Return value:
  113. S_OK, if successful.
  114. E_INVALIDARG, if one of the arguments is null.
  115. Any HRESULT value other than S_OK return by the snap-in.
  116. --*/
  117. {
  118. if (NULL == i_lpIDataObject)
  119. return S_OK;
  120. RETURN_INVALIDARG_IF_NULL(i_lpPropSheetCallback);
  121. RETURN_INVALIDARG_IF_NULL(i_lhandle);
  122. HRESULT hr = E_UNEXPECTED;
  123. CMmcDisplay* pCMmcDisplayObj = NULL;
  124. // Get the display object from IDataObject
  125. hr = GetDisplayObject(i_lpIDataObject, &pCMmcDisplayObj);
  126. RETURN_IF_FAILED(hr);
  127. // Use the virtual method CreatePropertyPages in the display object
  128. hr = pCMmcDisplayObj->CreatePropertyPages(i_lpPropSheetCallback, i_lhandle);
  129. RETURN_IF_FAILED(hr);
  130. return S_OK;
  131. }
  132. STDMETHODIMP CDfsSnapinScopeManager::QueryPagesFor(
  133. IN LPDATAOBJECT i_lpIDataObject
  134. )
  135. /*++
  136. Routine Description:
  137. Called by the console to decide whether there are PropertyPages
  138. for the given node that should be displayed.
  139. We check, if the context is for scope or result(thereby skipping
  140. node manager) and if it is pass on the call to the Display object
  141. Arguments:
  142. i_lpDataObject - The IDataObject pointer which is used to get
  143. the DisplayObject.
  144. Return value:
  145. S_OK, if we want pages to be displayed. This is decided by the display
  146. object
  147. S_FALSE, if we don't want pages to be display.
  148. E_INVALIDARG, if one of the arguments is null.
  149. Any HRESULT value other than S_OK return by the snap-in.
  150. --*/
  151. {
  152. if (NULL == i_lpIDataObject)
  153. return S_OK;
  154. HRESULT hr = E_UNEXPECTED;
  155. CMmcDisplay* pMmcDisplay = NULL;
  156. CMmcDisplay* pCMmcDisplayObj = NULL;
  157. // Get the display object from IDataObject
  158. hr = GetDisplayObject(i_lpIDataObject, &pCMmcDisplayObj);
  159. RETURN_IF_FAILED(hr);
  160. return pCMmcDisplayObj->QueryPagesFor();
  161. }
  162. STDMETHODIMP
  163. CDfsSnapinScopeManager::DoNotifyPropertyChange(
  164. IN LPDATAOBJECT i_lpDataObject,
  165. IN LPARAM i_lparam
  166. )
  167. /*++
  168. Routine Description:
  169. Take action on notify event MMCN_PROPERTY_CHANGE.
  170. Arguments:
  171. i_lpDataObject - The IDataObject pointer. This is NULL here!!
  172. i_lparam - Whatever was sent to Notify. This is the display object
  173. --*/
  174. {
  175. RETURN_INVALIDARG_IF_NULL(i_lparam);
  176. HRESULT hr = E_UNEXPECTED;
  177. CMmcDisplay* pCMmcDisplayObj = (CMmcDisplay*)i_lparam;
  178. // Pass the notification to the display object.
  179. hr = pCMmcDisplayObj->PropertyChanged();
  180. RETURN_IF_FAILED(hr);
  181. return S_OK;
  182. }
  183. STDMETHODIMP
  184. CDfsSnapinScopeManager::GetWatermarks(
  185. IN LPDATAOBJECT pDataObject,
  186. IN HBITMAP* lphWatermark,
  187. IN HBITMAP* lphHeader,
  188. IN HPALETTE* lphPalette,
  189. IN BOOL* bStretch
  190. )
  191. {
  192. /*++
  193. Routine Description:
  194. Gives the water mark bitmaps to mmc to display for new style pages.
  195. Arguments:
  196. lphWatermark - Bitmap mark for body
  197. lphHeader - Bitmap for header
  198. lphPalette - Pallete
  199. bStretch - Strech / not?
  200. Return value:
  201. S_OK, if successful.
  202. HRESULT sent by methods called, if it is not S_OK.
  203. --*/
  204. // Load the bitmap for bofy water mark.
  205. *lphWatermark = (HBITMAP)LoadImage (
  206. _Module.GetModuleInstance(),
  207. MAKEINTRESOURCE(IDB_CREATE_DFSROOT_WATERMARK),
  208. IMAGE_BITMAP,
  209. 0,
  210. 0,
  211. LR_SHARED | LR_CREATEDIBSECTION
  212. );
  213. if(NULL == *lphWatermark)
  214. {
  215. return E_UNEXPECTED;
  216. }
  217. // Load the bitmap for header.
  218. *lphHeader = (HBITMAP)LoadImage (
  219. _Module.GetModuleInstance(),
  220. MAKEINTRESOURCE(IDB_CREATE_DFSROOT_HEADER),
  221. IMAGE_BITMAP,
  222. 0,
  223. 0,
  224. LR_SHARED | LR_CREATEDIBSECTION
  225. );
  226. if(NULL == *lphHeader)
  227. {
  228. return E_UNEXPECTED;
  229. }
  230. // Do not stretch.
  231. *bStretch = FALSE;
  232. *lphPalette = NULL; // Defaukt color palette.
  233. return S_OK;
  234. }