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.

236 lines
6.4 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. return S_OK;
  64. // if (spImageList->ImageListSetStrip((long*)hBitmap16,
  65. // (long*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  66. if (spImageList->ImageListSetStrip((LONG_PTR*)hBitmap16,
  67. (LONG_PTR*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  68. {
  69. ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  70. return E_UNEXPECTED;
  71. }
  72. DeleteObject(hBitmap16);
  73. DeleteObject(hBitmap32);
  74. // setting root node handle to main window
  75. // so that the root node may disable the main
  76. // window when a wizard is active
  77. HWND hwndMainWindow = 0;
  78. m_spConsole->GetMainWindow(&hwndMainWindow);
  79. if (m_pNode)
  80. {
  81. ((CRootNode*)m_pNode)->SetMainWindow(hwndMainWindow);
  82. }
  83. return S_OK;
  84. }
  85. STDMETHODIMP
  86. CDomMigratorComponent::AddMenuItems(
  87. LPDATAOBJECT pDataObject,
  88. LPCONTEXTMENUCALLBACK piCallback,
  89. long * pInsertionAllowed
  90. )
  91. {
  92. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenuImpl::AddMenuItems\n"));
  93. HRESULT hr = E_POINTER;
  94. ATLASSERT(pDataObject != NULL);
  95. if (pDataObject == NULL)
  96. {
  97. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenu::AddMenuItems called with pDataObject==NULL\n"));
  98. }
  99. else
  100. {
  101. CSnapInItem * pItem;
  102. DATA_OBJECT_TYPES type;
  103. hr = m_pComponentData->GetDataClass(pDataObject, &pItem, &type);
  104. if (SUCCEEDED(hr))
  105. {
  106. hr = pItem->AddMenuItems(piCallback, pInsertionAllowed, type);
  107. }
  108. else
  109. { // is it multiselection data
  110. SMMCDataObjects *pMsDataObjs = CMultiSelectItemDataObject::ExtractMSDataObjects(pDataObject);
  111. if ((pMsDataObjs) && ( pMsDataObjs->count ))
  112. {
  113. LPDATAOBJECT pMsData;
  114. pMsData = pMsDataObjs->lpDataObject[0];
  115. FORMATETC format={(CLIPFORMAT)CMultiSelectItemDataObject::s_cfMsObjTypes,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  116. hr = pMsData->QueryGetData(&format);
  117. if ( hr == S_OK )
  118. {
  119. hr = ((CMultiSelectItemDataObject *)pMsData)->AddMenuItems(piCallback, pInsertionAllowed, type);
  120. }
  121. }
  122. }
  123. }
  124. return hr;
  125. }
  126. STDMETHODIMP CDomMigratorComponent::Command(long lCommandID,
  127. LPDATAOBJECT pDataObject)
  128. {
  129. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenuImpl::Command\n"));
  130. HRESULT hr = E_POINTER;
  131. ATLASSERT(pDataObject != NULL);
  132. if (pDataObject == NULL)
  133. ATLTRACE2(atlTraceSnapin, 0, _T("IExtendContextMenu::Command called with pDataObject==NULL\n"));
  134. else
  135. {
  136. CSnapInItem * pItem;
  137. DATA_OBJECT_TYPES type;
  138. hr = m_pComponentData->GetDataClass(pDataObject, &pItem, &type);
  139. if (SUCCEEDED(hr))
  140. {
  141. hr = pItem->Command(lCommandID, (CSnapInObjectRootBase*)this, type);
  142. }
  143. else
  144. { // is it multiselection data
  145. SMMCDataObjects *pMsDataObjs = CMultiSelectItemDataObject::ExtractMSDataObjects(pDataObject);
  146. if ((pMsDataObjs) && ( pMsDataObjs->count ))
  147. {
  148. LPDATAOBJECT pMsData;
  149. pMsData = pMsDataObjs->lpDataObject[0];
  150. FORMATETC format={(CLIPFORMAT)CMultiSelectItemDataObject::s_cfMsObjTypes,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
  151. HRESULT hr = pMsData->QueryGetData(&format);
  152. if ( hr == S_OK )
  153. {
  154. hr = ((CMultiSelectItemDataObject *)pMsData)->Command(lCommandID, (CSnapInObjectRootBase*)this, type);
  155. }
  156. }
  157. }
  158. }
  159. return hr;
  160. }
  161. CDomMigrator::CDomMigrator()
  162. {
  163. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  164. m_pNode = new CRootNode;
  165. _ASSERTE(m_pNode != NULL);
  166. m_pComponentData = this;
  167. m_lpszSnapinHelpFile.LoadString(IDS_HELPFILE);
  168. }
  169. CDomMigrator::~CDomMigrator()
  170. {
  171. delete m_pNode;
  172. m_pNode = NULL;
  173. }
  174. /*
  175. On the Help menu, there should be 1 Help Topics option that displays a Contents list with both our Help and the MMC Help.
  176. */
  177. STDMETHODIMP CDomMigrator::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  178. {
  179. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  180. if (lpCompiledHelpFile == NULL)
  181. return E_INVALIDARG;
  182. if (m_lpszSnapinHelpFile.IsEmpty() )
  183. {
  184. *lpCompiledHelpFile = NULL;
  185. return E_NOTIMPL;
  186. }
  187. return GetHelpFileFullPath(lpCompiledHelpFile);
  188. }
  189. STDMETHODIMP CDomMigrator::GetLinkedTopics(LPOLESTR* lpCompiledHelpFile)
  190. {
  191. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  192. if (lpCompiledHelpFile == NULL)
  193. return E_INVALIDARG;
  194. return GetHelpFileFullPath(lpCompiledHelpFile);
  195. }