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.

71 lines
2.1 KiB

  1. // CMenuExt.cpp : Implementation of CCMenuExt
  2. #include "stdafx.h"
  3. #include "DSAdminExt.h"
  4. #include "CMenuExt.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CCMenuExt
  7. ///////////////////////////////
  8. // Interface IExtendContextMenu
  9. ///////////////////////////////
  10. HRESULT CCMenuExt::AddMenuItems(
  11. /* [in] */ LPDATAOBJECT piDataObject,
  12. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  13. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  14. {
  15. HRESULT hr = S_FALSE;
  16. if (NULL == piDataObject)
  17. return hr;
  18. CONTEXTMENUITEM menuItemsTask[] =
  19. {
  20. {
  21. L"DSAdmin Extension Sample Menu Item", L"Inserted by DSAdminExt.dll sample snap-in",
  22. 1, CCM_INSERTIONPOINTID_3RDPARTY_TASK , 0, 0
  23. },
  24. { NULL, NULL, 0, 0, 0 }
  25. };
  26. // Loop through and add each of the menu items
  27. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK)
  28. {
  29. for (CONTEXTMENUITEM *m = menuItemsTask; m->strName; m++)
  30. {
  31. hr = piCallback->AddItem(m);
  32. if (FAILED(hr))
  33. break;
  34. }
  35. }
  36. return hr;
  37. }
  38. HRESULT CCMenuExt::Command(
  39. /* [in] */ long lCommandID,
  40. /* [in] */ LPDATAOBJECT piDataObject)
  41. {
  42. _TCHAR pszName[255];
  43. HRESULT hr = ExtractString(piDataObject, s_cfDisplayName, pszName, sizeof(pszName));
  44. LPOLESTR lpDest = NULL;
  45. AllocOleStr(&lpDest, pszName);
  46. if (SUCCEEDED(hr)) {
  47. switch (lCommandID)
  48. {
  49. case 1:
  50. ::MessageBox(NULL, lpDest, _T("Message from DSAdminExt.dll"), MB_OK|MB_ICONEXCLAMATION);
  51. break;
  52. }
  53. }
  54. else
  55. ::MessageBox(NULL, _T("Multiple objects selected"), _T("DSAdminExt.dll Sample"), MB_OK|MB_ICONEXCLAMATION);
  56. // Free memory.
  57. CoTaskMemFree(lpDest) ;
  58. return S_OK;
  59. }