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.

242 lines
6.8 KiB

  1. #include "stdafx.h"
  2. #include "DomMigSI.h"
  3. #include "DomMigr.h"
  4. #include "MultiSel.h"
  5. #include <windows.h>
  6. #include "TReg.hpp"
  7. #include "ResStr.h"
  8. HRESULT GetHelpFileFullPath( BSTR *bstrHelp )
  9. {
  10. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  11. CString strPath, strName;
  12. TRegKey key;
  13. TCHAR szModule[2*_MAX_PATH];
  14. DWORD dwReturn = 0;
  15. LPOLESTR lpHelpFile;
  16. //mmc requires we use CoTaskMemAlloc to allocate memory returned from
  17. //this function
  18. lpHelpFile = (LPOLESTR) CoTaskMemAlloc( 2 * MAX_PATH * sizeof(WCHAR) );
  19. if ( !lpHelpFile )
  20. {
  21. return E_OUTOFMEMORY;
  22. }
  23. dwReturn = key.Open(GET_STRING(IDS_DOMAIN_ADMIN_REGKEY),HKEY_LOCAL_MACHINE);
  24. if ( ! dwReturn )
  25. {
  26. dwReturn = key.ValueGetStr(L"Directory",szModule,DIM(szModule));
  27. if (! dwReturn )
  28. {
  29. strPath = szModule;
  30. strPath += L"\\";
  31. strName.LoadString(IDS_HELPFILE);
  32. strPath += strName;
  33. }
  34. }
  35. wcscpy(lpHelpFile, strPath);
  36. *bstrHelp = lpHelpFile;
  37. return HRESULT_FROM_WIN32(dwReturn);
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CDomMigratorComponentData
  41. static const GUID CDomMigratorGUID_NODETYPE =
  42. { 0xe1975d72, 0x3f8e, 0x11d3, { 0x99, 0xee, 0x0, 0xc0, 0x4f, 0x39, 0xbd, 0x92 } };
  43. HRESULT CDomMigrator::Initialize(LPUNKNOWN pUnknown)
  44. {
  45. HRESULT hr = IComponentDataImpl<CDomMigrator, CDomMigratorComponent >::Initialize(pUnknown);
  46. if (FAILED(hr))
  47. return hr;
  48. CComPtr<IImageList> spImageList;
  49. if (m_spConsole->QueryScopeImageList(&spImageList) != S_OK)
  50. {
  51. ATLTRACE(_T("IConsole::QueryScopeImageList failed\n"));
  52. return E_UNEXPECTED;
  53. }
  54. // Load bitmaps associated with the scope pane
  55. // and add them to the image list
  56. // Loads the default bitmaps generated by the wizard
  57. // Change as required
  58. HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_TOOL_16));
  59. if (hBitmap16 == NULL)
  60. return S_OK;
  61. HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_TOOL_32));
  62. if (hBitmap32 == NULL)
  63. {
  64. DeleteObject(hBitmap16);
  65. return S_OK;
  66. }
  67. // if (spImageList->ImageListSetStrip((long*)hBitmap16,
  68. // (long*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  69. if (spImageList->ImageListSetStrip((LONG_PTR*)hBitmap16,
  70. (LONG_PTR*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  71. {
  72. ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  73. DeleteObject(hBitmap16);
  74. DeleteObject(hBitmap32);
  75. return E_UNEXPECTED;
  76. }
  77. DeleteObject(hBitmap16);
  78. DeleteObject(hBitmap32);
  79. // setting root node handle to main window
  80. // so that the root node may disable the main
  81. // window when a wizard is active
  82. HWND hwndMainWindow = 0;
  83. m_spConsole->GetMainWindow(&hwndMainWindow);
  84. if (m_pNode)
  85. {
  86. ((CRootNode*)m_pNode)->SetMainWindow(hwndMainWindow);
  87. }
  88. return S_OK;
  89. }
  90. STDMETHODIMP
  91. CDomMigratorComponent::AddMenuItems(
  92. LPDATAOBJECT pDataObject,
  93. LPCONTEXTMENUCALLBACK piCallback,
  94. long * pInsertionAllowed
  95. )
  96. {
  97. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenuImpl::AddMenuItems\n"));
  98. HRESULT hr = E_POINTER;
  99. ATLASSERT(pDataObject != NULL);
  100. if (pDataObject == NULL)
  101. {
  102. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenu::AddMenuItems called with pDataObject==NULL\n"));
  103. }
  104. else
  105. {
  106. CSnapInItem * pItem;
  107. DATA_OBJECT_TYPES type;
  108. hr = m_pComponentData->GetDataClass(pDataObject, &pItem, &type);
  109. if (SUCCEEDED(hr))
  110. {
  111. hr = pItem->AddMenuItems(piCallback, pInsertionAllowed, type);
  112. }
  113. else
  114. { // is it multiselection data
  115. SMMCDataObjects *pMsDataObjs = CMultiSelectItemDataObject::ExtractMSDataObjects(pDataObject);
  116. if ((pMsDataObjs) && ( pMsDataObjs->count ))
  117. {
  118. LPDATAOBJECT pMsData;
  119. pMsData = pMsDataObjs->lpDataObject[0];
  120. FORMATETC format={(CLIPFORMAT)CMultiSelectItemDataObject::s_cfMsObjTypes,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  121. hr = pMsData->QueryGetData(&format);
  122. if ( hr == S_OK )
  123. {
  124. hr = ((CMultiSelectItemDataObject *)pMsData)->AddMenuItems(piCallback, pInsertionAllowed, type);
  125. }
  126. }
  127. }
  128. }
  129. return hr;
  130. }
  131. STDMETHODIMP CDomMigratorComponent::Command(long lCommandID,
  132. LPDATAOBJECT pDataObject)
  133. {
  134. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenuImpl::Command\n"));
  135. HRESULT hr = E_POINTER;
  136. ATLASSERT(pDataObject != NULL);
  137. if (pDataObject == NULL)
  138. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenu::Command called with pDataObject==NULL\n"));
  139. else
  140. {
  141. CSnapInItem * pItem;
  142. DATA_OBJECT_TYPES type;
  143. hr = m_pComponentData->GetDataClass(pDataObject, &pItem, &type);
  144. if (SUCCEEDED(hr))
  145. {
  146. hr = pItem->Command(lCommandID, (CSnapInObjectRootBase*)this, type);
  147. }
  148. else
  149. { // is it multiselection data
  150. SMMCDataObjects *pMsDataObjs = CMultiSelectItemDataObject::ExtractMSDataObjects(pDataObject);
  151. if ((pMsDataObjs) && ( pMsDataObjs->count ))
  152. {
  153. LPDATAOBJECT pMsData;
  154. pMsData = pMsDataObjs->lpDataObject[0];
  155. FORMATETC format={(CLIPFORMAT)CMultiSelectItemDataObject::s_cfMsObjTypes,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  156. HRESULT hr = pMsData->QueryGetData(&format);
  157. if ( hr == S_OK )
  158. {
  159. hr = ((CMultiSelectItemDataObject *)pMsData)->Command(lCommandID, (CSnapInObjectRootBase*)this, type);
  160. }
  161. }
  162. }
  163. }
  164. return hr;
  165. }
  166. CDomMigrator::CDomMigrator()
  167. {
  168. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  169. m_pNode = new CRootNode;
  170. _ASSERTE(m_pNode != NULL);
  171. m_pComponentData = this;
  172. m_lpszSnapinHelpFile.LoadString(IDS_HELPFILE);
  173. }
  174. CDomMigrator::~CDomMigrator()
  175. {
  176. if (m_pNode)
  177. delete m_pNode;
  178. m_pNode = NULL;
  179. }
  180. /*
  181. On the Help menu, there should be 1 Help Topics option that displays a Contents list with both our Help and the MMC Help.
  182. */
  183. STDMETHODIMP CDomMigrator::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  184. {
  185. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  186. if (lpCompiledHelpFile == NULL)
  187. return E_INVALIDARG;
  188. if (m_lpszSnapinHelpFile.IsEmpty() )
  189. {
  190. *lpCompiledHelpFile = NULL;
  191. return E_NOTIMPL;
  192. }
  193. return GetHelpFileFullPath(lpCompiledHelpFile);
  194. }
  195. STDMETHODIMP CDomMigrator::GetLinkedTopics(LPOLESTR* lpCompiledHelpFile)
  196. {
  197. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  198. if (lpCompiledHelpFile == NULL)
  199. return E_INVALIDARG;
  200. return GetHelpFileFullPath(lpCompiledHelpFile);
  201. }