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.

180 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: menusp.cxx
  7. //
  8. // Contents: Implementation of IContextMenu
  9. //
  10. // History: 20-Dec-95 BruceFo Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include "util.hxx"
  16. #include "dutil.hxx"
  17. #include "menusp.hxx"
  18. #include "menuutil.hxx"
  19. #include "shares.h"
  20. #include "resource.h"
  21. #ifdef WIZARDS
  22. CSharesCMSpecial::CSharesCMSpecial(
  23. IN HWND hwnd
  24. )
  25. :
  26. m_ulRefs(0),
  27. m_hwnd(hwnd),
  28. m_pidl(NULL),
  29. m_psf(NULL)
  30. {
  31. AddRef();
  32. }
  33. HRESULT
  34. CSharesCMSpecial::InitInstance(
  35. IN PWSTR pszMachine,
  36. IN LPCITEMIDLIST pidl,
  37. IN IShellFolder* psf
  38. )
  39. {
  40. m_pszMachine = pszMachine;
  41. m_pidl = ILClone(pidl);
  42. if (NULL == m_pidl)
  43. {
  44. return E_OUTOFMEMORY;
  45. }
  46. m_psf = psf;
  47. m_psf->AddRef();
  48. return S_OK;
  49. }
  50. CSharesCMSpecial::~CSharesCMSpecial()
  51. {
  52. ILFree(m_pidl);
  53. m_pidl = NULL;
  54. m_psf->Release();
  55. m_psf = NULL;
  56. }
  57. STDMETHODIMP
  58. CSharesCMSpecial::QueryContextMenu(
  59. HMENU hmenu,
  60. UINT indexMenu,
  61. UINT idCmdFirst,
  62. UINT idCmdLast,
  63. UINT uFlags
  64. )
  65. {
  66. UINT idMerge;
  67. if (uFlags & CMF_DVFILE)
  68. {
  69. idMerge = POPUP_SPECIAL_FILE;
  70. }
  71. else
  72. {
  73. idMerge = POPUP_SPECIAL;
  74. }
  75. QCMINFO qcm = { hmenu, indexMenu, idCmdFirst, idCmdLast };
  76. MyMergeMenu(g_hInstance, idMerge, 0, &qcm);
  77. SetMenuDefaultItem(hmenu, idCmdFirst + FSIDM_OPENSPECIAL, FALSE);
  78. return ResultFromShort(qcm.idCmdFirst - idCmdFirst);
  79. }
  80. STDMETHODIMP
  81. CSharesCMSpecial::InvokeCommand(
  82. LPCMINVOKECOMMANDINFO lpici
  83. )
  84. {
  85. HRESULT hr = S_OK;
  86. LPIDSHARE pids;
  87. UINT i;
  88. UINT idCmd = (UINT)LOWORD((DWORD)lpici->lpVerb);
  89. if (HIWORD(lpici->lpVerb))
  90. {
  91. // Deal with string commands
  92. PSTR pszCmd = (PSTR)lpici->lpVerb;
  93. // Check for "link" that comes from the toolbar or the shell view.
  94. if (0 == lstrcmpA(pszCmd, "link"))
  95. {
  96. idCmd = SHARED_FILE_LINK;
  97. }
  98. else
  99. {
  100. return E_INVALIDARG;
  101. }
  102. }
  103. switch(idCmd)
  104. {
  105. case FSIDM_OPENSPECIAL:
  106. {
  107. pids = (LPIDSHARE)m_pidl;
  108. hr = ShareDoSpecial(m_hwnd, m_pszMachine, Share_GetFlags(pids));
  109. CHECK_HRESULT(hr);
  110. break;
  111. }
  112. case SHARED_FILE_LINK:
  113. {
  114. UINT dwfInOut = 0;
  115. IDataObject* pDataObject;
  116. hr = m_psf->GetUIObjectOf(
  117. lpici->hwnd,
  118. 1,
  119. (LPCITEMIDLIST*)&m_pidl,
  120. IID_IDataObject,
  121. &dwfInOut,
  122. (LPVOID*)&pDataObject);
  123. if (SUCCEEDED(hr))
  124. {
  125. SHCreateLinks(
  126. lpici->hwnd,
  127. NULL,
  128. pDataObject,
  129. SHCL_USETEMPLATE,
  130. NULL);
  131. pDataObject->Release();
  132. }
  133. break;
  134. }
  135. } // switch(wParam)
  136. return hr;
  137. }
  138. STDMETHODIMP
  139. CSharesCMSpecial::GetCommandString(
  140. UINT_PTR idCmd,
  141. UINT uType,
  142. UINT * pwReserved,
  143. LPSTR pszName,
  144. UINT cchMax
  145. )
  146. {
  147. *((LPWSTR)pszName) = TEXT('\0');
  148. if (uType == GCS_HELPTEXT)
  149. {
  150. LoadStringW(g_hInstance, idCmd + IDS_MH_FSIDM_FIRST, (LPWSTR)pszName, cchMax);
  151. return NOERROR;
  152. }
  153. return E_FAIL;
  154. }
  155. #endif // WIZARDS