ReactOS  0.4.14-dev-998-g623dd26
CSendToMenu Class Reference

#include <CSendToMenu.h>

Inheritance diagram for CSendToMenu:
Collaboration diagram for CSendToMenu:

Classes

struct  SENDTO_ITEM
 

Public Member Functions

 CSendToMenu ()
 
 ~CSendToMenu ()
 
STDMETHODIMP QueryContextMenu (HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
 
STDMETHODIMP InvokeCommand (LPCMINVOKECOMMANDINFO lpcmi)
 
STDMETHODIMP GetCommandString (UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen)
 
STDMETHODIMP HandleMenuMsg2 (UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
 
STDMETHODIMP HandleMenuMsg (UINT uMsg, WPARAM wParam, LPARAM lParam)
 
STDMETHODIMP Initialize (PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Private Member Functions

HRESULT LoadAllItems (HWND hwnd)
 
void UnloadAllItems ()
 
BOOL FolderHasAnyItems () const
 
HRESULT CreateSendToFiles (LPCWSTR pszSendTo)
 
UINT InsertSendToItems (HMENU hMenu, UINT idFirst, UINT idMenu)
 
SENDTO_ITEMFindItemFromIdOffset (UINT IdOffset)
 
HRESULT DoSendToItem (SENDTO_ITEM *pItem, LPCMINVOKECOMMANDINFO lpici)
 
HRESULT DoDrop (IDataObject *pDataObject, IDropTarget *pDropTarget)
 
HRESULT GetSpecialFolder (HWND hwnd, IShellFolder **ppFolder, int csidl, PIDLIST_ABSOLUTE *ppidl=NULL)
 
HRESULT GetUIObjectFromPidl (HWND hwnd, PIDLIST_ABSOLUTE pidl, REFIID riid, LPVOID *ppvOut)
 

Private Attributes

HMENU m_hSubMenu
 
SENDTO_ITEMm_pItems
 
UINT m_idCmdFirst
 
CComPtr< IShellFolderm_pDesktop
 
CComPtr< IShellFolderm_pSendTo
 
CComPtr< IDataObjectm_pDataObject
 

Additional Inherited Members

- Public Types inherited from IContextMenu3
typedef IContextMenu3LPCONTEXTMENU3
 
- Public Types inherited from IContextMenu2
typedef IContextMenu2LPCONTEXTMENU2
 
- Public Types inherited from IContextMenu
typedef struct IContextMenu::tagCMINVOKECOMMANDINFO CMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMINVOKECOMMANDINFOLPCMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMInvokeCommandInfoEx CMINVOKECOMMANDINFOEX
 
typedef struct IContextMenu::tagCMInvokeCommandInfoExLPCMINVOKECOMMANDINFOEX
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Public Types inherited from IShellExtInit
typedef IShellExtInitLPSHELLEXTINIT
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 
- Public Attributes inherited from IContextMenu
CMIC_MASK_NOZONECHECKS typedef IContextMenuLPCONTEXTMENU
 
- Static Public Attributes inherited from IContextMenu
static CMDSTR_VIEWDETAILSW(const WCHAR []) const WCHAR CMDSTR_NEWFOLDERW [] = {'N','e','w','F','o','l','d','e','r',0}
 
static const WCHAR CMDSTR_VIEWLISTW [] = {'V','i','e','w','L','i','s','t',0}
 
static const WCHAR CMDSTR_VIEWDETAILSW [] = {'V','i','e','w','D','e','t','a','i','l','s',0}
 

Detailed Description

Definition at line 26 of file CSendToMenu.h.

Constructor & Destructor Documentation

◆ CSendToMenu()

CSendToMenu::CSendToMenu ( )

Definition at line 25 of file CSendToMenu.cpp.

26  : m_hSubMenu(NULL)
27  , m_pItems(NULL)
28  , m_idCmdFirst(0)
29 {
31  if (FAILED(hr))
32  {
33  ERR("SHGetDesktopFolder: %08lX\n", hr);
34  }
35 
37 }
HRESULT hr
Definition: shlfolder.c:183
CComPtr< IShellFolder > m_pSendTo
Definition: CSendToMenu.h:66
smooth NULL
Definition: ftsmooth.c:416
SENDTO_ITEM * m_pItems
Definition: CSendToMenu.h:62
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
LONG HRESULT
Definition: typedefs.h:78
#define CSIDL_SENDTO
Definition: shlobj.h:2020
HMENU m_hSubMenu
Definition: CSendToMenu.h:61
UINT m_idCmdFirst
Definition: CSendToMenu.h:63
#define ERR(fmt,...)
Definition: debug.h:109
HRESULT GetSpecialFolder(HWND hwnd, IShellFolder **ppFolder, int csidl, PIDLIST_ABSOLUTE *ppidl=NULL)
CComPtr< IShellFolder > m_pDesktop
Definition: CSendToMenu.h:65

◆ ~CSendToMenu()

CSendToMenu::~CSendToMenu ( )

Definition at line 39 of file CSendToMenu.cpp.

40 {
42 
43  if (m_hSubMenu)
44  {
46  m_hSubMenu = NULL;
47  }
48 }
smooth NULL
Definition: ftsmooth.c:416
HMENU m_hSubMenu
Definition: CSendToMenu.h:61
BOOL WINAPI DestroyMenu(_In_ HMENU)
void UnloadAllItems()

Member Function Documentation

◆ CreateSendToFiles()

HRESULT CSendToMenu::CreateSendToFiles ( LPCWSTR  pszSendTo)
private

Definition at line 258 of file CSendToMenu.cpp.

259 {
260  WCHAR szTarget[MAX_PATH];
261  WCHAR szSendToFile[MAX_PATH];
262  WCHAR szShell32[MAX_PATH];
263  HRESULT hr;
264 
265  /* create my documents */
267 
268  StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
269  PathAppendW(szSendToFile, PathFindFileNameW(szTarget));
270  StringCbCatW(szSendToFile, sizeof(szSendToFile), L".lnk");
271 
272  GetSystemDirectoryW(szShell32, ARRAY_SIZE(szShell32));
273  PathAppendW(szShell32, L"shell32.dll");
274  hr = CreateShellLink(szSendToFile, szTarget, NULL, NULL, NULL,
275  szShell32, -IDI_SHELL_MY_DOCUMENTS, NULL);
276  if (FAILED_UNEXPECTEDLY(hr))
277  ERR("CreateShellLink(%S, %S) failed!\n", szSendToFile, szTarget);
278 
279  /* create desklink */
280  StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
281  LoadStringW(shell32_hInstance, IDS_DESKLINK, szTarget, _countof(szTarget));
282  StringCbCatW(szTarget, sizeof(szTarget), L".DeskLink");
283  PathAppendW(szSendToFile, szTarget);
284  if (!CreateEmptyFile(szSendToFile))
285  {
286  ERR("CreateEmptyFile\n");
287  }
288 
289  /* create zipped compressed folder */
290  HINSTANCE hZipFldr =
292  if (hZipFldr)
293  {
294 #define IDS_FRIENDLYNAME 10195
295  LoadStringW(hZipFldr, IDS_FRIENDLYNAME, szTarget, _countof(szTarget));
296 #undef IDS_FRIENDLYNAME
297  FreeLibrary(hZipFldr);
298 
299  StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
300  PathAppendW(szSendToFile, szTarget);
301  StringCbCatW(szSendToFile, sizeof(szSendToFile), L".ZFSendToTarget");
302  if (!CreateEmptyFile(szSendToFile))
303  {
304  ERR("CreateEmptyFile\n");
305  }
306  }
307 
308  return S_OK;
309 }
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: fontsub.cpp:30
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
static HRESULT CreateShellLink(LPCWSTR pszLinkPath, LPCWSTR pszTargetPath OPTIONAL, LPCITEMIDLIST pidlTarget OPTIONAL, LPCWSTR pszArg OPTIONAL, LPCWSTR pszDir OPTIONAL, LPCWSTR pszIconPath OPTIONAL, INT iIconNr OPTIONAL, LPCWSTR pszComment OPTIONAL)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
static BOOL CreateEmptyFile(LPCWSTR pszFile)
#define CSIDL_MYDOCUMENTS
Definition: shlobj.h:2023
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
smooth NULL
Definition: ftsmooth.c:416
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
#define FreeLibrary(x)
Definition: compat.h:413
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_DESKLINK
Definition: shresdef.h:232
#define ERR(fmt,...)
Definition: debug.h:109
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:338
#define S_OK
Definition: intsafe.h:59
#define IDI_SHELL_MY_DOCUMENTS
Definition: shresdef.h:605
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2685
#define ARRAY_SIZE(a)
Definition: main.h:24
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
#define IDS_FRIENDLYNAME
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by LoadAllItems().

◆ DoDrop()

HRESULT CSendToMenu::DoDrop ( IDataObject pDataObject,
IDropTarget pDropTarget 
)
private

Definition at line 50 of file CSendToMenu.cpp.

51 {
52  DWORD dwEffect = DROPEFFECT_MOVE | DROPEFFECT_COPY | DROPEFFECT_LINK;
53 
55  BOOL bCtrl = (GetAsyncKeyState(VK_CONTROL) < 0);
56 
57  // THIS CODE IS NOT HUMAN-FRIENDLY. SORRY.
58  // (We have to translate a SendTo action to a Drop action)
59  DWORD dwKeyState = MK_LBUTTON;
60  if (bShift && bCtrl)
61  dwKeyState |= MK_SHIFT | MK_CONTROL;
62  else if (!bShift)
63  dwKeyState |= MK_CONTROL;
64  if (bCtrl)
65  dwKeyState |= MK_SHIFT;
66 
67  POINTL ptl = { 0, 0 };
68  HRESULT hr = pDropTarget->DragEnter(pDataObject, dwKeyState, ptl, &dwEffect);
70  {
71  pDropTarget->DragLeave();
72  return hr;
73  }
74 
75  if (dwEffect == DROPEFFECT_NONE)
76  {
77  ERR("DROPEFFECT_NONE\n");
78  pDropTarget->DragLeave();
79  return E_FAIL;
80  }
81 
82  // THIS CODE IS NOT HUMAN-FRIENDLY. SORRY.
83  // (We have to translate a SendTo action to a Drop action)
84  if (bShift && bCtrl)
85  dwEffect = DROPEFFECT_LINK;
86  else if (!bShift)
87  dwEffect = DROPEFFECT_MOVE;
88  else
89  dwEffect = DROPEFFECT_COPY;
90 
91  hr = pDropTarget->Drop(pDataObject, dwKeyState, ptl, &dwEffect);
93  return hr;
94 
95  return hr;
96 }
#define MK_SHIFT
Definition: winuser.h:2344
HRESULT hr
Definition: shlfolder.c:183
#define MK_LBUTTON
Definition: winuser.h:2342
volatile BOOLEAN bShift
Definition: shell.c:71
#define E_FAIL
Definition: ddrawi.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VK_SHIFT
Definition: winuser.h:2177
HRESULT DragEnter([in, unique] IDataObject *pDataObj, [in] DWORD grfKeyState, [in] POINTL pt, [in, out] DWORD *pdwEffect)
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
SHORT WINAPI GetAsyncKeyState(_In_ int)
#define ERR(fmt,...)
Definition: debug.h:109
HRESULT Drop([in, unique] IDataObject *pDataObj, [in] DWORD grfKeyState, [in] POINTL pt, [in, out] DWORD *pdwEffect)
#define MK_CONTROL
Definition: winuser.h:2345
#define VK_CONTROL
Definition: winuser.h:2178
HRESULT DragLeave()

Referenced by DoSendToItem().

◆ DoSendToItem()

HRESULT CSendToMenu::DoSendToItem ( SENDTO_ITEM pItem,
LPCMINVOKECOMMANDINFO  lpici 
)
private

Definition at line 424 of file CSendToMenu.cpp.

425 {
426  if (!m_pDataObject)
427  {
428  ERR("!m_pDataObject\n");
429  return E_FAIL;
430  }
431 
432  HRESULT hr;
433  CComPtr<IDropTarget> pDropTarget;
434  hr = m_pSendTo->GetUIObjectOf(NULL, 1, &pItem->pidlChild, IID_IDropTarget,
435  NULL, (LPVOID *)&pDropTarget);
436  if (FAILED_UNEXPECTEDLY(hr))
437  return hr;
438 
439  hr = DoDrop(m_pDataObject, pDropTarget);
440  if (FAILED_UNEXPECTEDLY(hr))
441  return hr;
442 
443  return hr;
444 }
CComPtr< IDataObject > m_pDataObject
Definition: CSendToMenu.h:67
HRESULT hr
Definition: shlfolder.c:183
CComPtr< IShellFolder > m_pSendTo
Definition: CSendToMenu.h:66
#define E_FAIL
Definition: ddrawi.h:102
HRESULT DoDrop(IDataObject *pDataObject, IDropTarget *pDropTarget)
Definition: CSendToMenu.cpp:50
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by InvokeCommand().

◆ FindItemFromIdOffset()

CSendToMenu::SENDTO_ITEM * CSendToMenu::FindItemFromIdOffset ( UINT  IdOffset)
private

Definition at line 411 of file CSendToMenu.cpp.

412 {
413  UINT idCmd = m_idCmdFirst + IdOffset;
414 
415  MENUITEMINFOW mii = { sizeof(mii) };
416  mii.fMask = MIIM_DATA;
417  if (GetMenuItemInfoW(m_hSubMenu, idCmd, FALSE, &mii))
418  return reinterpret_cast<SENDTO_ITEM *>(mii.dwItemData);
419 
420  ERR("GetMenuItemInfoW: %ld\n", GetLastError());
421  return NULL;
422 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
HMENU m_hSubMenu
Definition: CSendToMenu.h:61
UINT m_idCmdFirst
Definition: CSendToMenu.h:63
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int UINT
Definition: ndis.h:50
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3243

Referenced by InvokeCommand().

◆ FolderHasAnyItems()

BOOL CSendToMenu::FolderHasAnyItems ( ) const
private

Definition at line 159 of file CSendToMenu.cpp.

160 {
163 
164  PathAppendW(szPath, L"*");
165 
167  HANDLE hFind = FindFirstFileW(szPath, &find);
168  if (hFind == INVALID_HANDLE_VALUE)
169  return FALSE;
170 
171  BOOL bFound = FALSE;
172  do
173  {
174  if (wcscmp(find.cFileName, L".") == 0 ||
175  wcscmp(find.cFileName, L"..") == 0 ||
176  _wcsicmp(find.cFileName, L"desktop.ini") == 0)
177  {
178  continue;
179  }
180 
181  bFound = TRUE;
182  break;
183  } while (FindNextFileW(hFind, &find));
184 
185  FindClose(hFind);
186  return bFound;
187 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CSIDL_SENDTO
Definition: shlobj.h:2020
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2685
LPCWSTR szPath
Definition: env.c:35
static TAGID TAGID find
Definition: db.cpp:153
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by LoadAllItems().

◆ GetCommandString()

STDMETHODIMP CSendToMenu::GetCommandString ( UINT_PTR  idCommand,
UINT  uFlags,
UINT lpReserved,
LPSTR  lpszName,
UINT  uMaxNameLen 
)

Implements IContextMenu.

Definition at line 507 of file CSendToMenu.cpp.

512 {
513  FIXME("%p %lu %u %p %p %u\n", this,
514  idCmd, uType, pwReserved, pszName, cchMax);
515 
516  return E_NOTIMPL;
517 }
#define FIXME(fmt,...)
Definition: debug.h:110
UINT cchMax
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ GetSpecialFolder()

HRESULT CSendToMenu::GetSpecialFolder ( HWND  hwnd,
IShellFolder **  ppFolder,
int  csidl,
PIDLIST_ABSOLUTE ppidl = NULL 
)
private

Definition at line 100 of file CSendToMenu.cpp.

102 {
103  if (!ppFolder)
104  return E_POINTER;
105  *ppFolder = NULL;
106 
107  if (ppidl)
108  *ppidl = NULL;
109 
111  HRESULT hr = SHGetSpecialFolderLocation(hwnd, csidl, &pidl);
112  if (FAILED_UNEXPECTEDLY(hr))
113  return hr;
114 
115  IShellFolder *pFolder = NULL;
116  hr = m_pDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, &pFolder));
117 
118  if (ppidl)
119  *ppidl = pidl.Detach();
120 
121  if (FAILED_UNEXPECTEDLY(hr))
122  return hr;
123 
124  *ppFolder = pFolder;
125  return hr;
126 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HRESULT hr
Definition: shlfolder.c:183
#define IID_PPV_ARG(Itype, ppType)
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2806
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define E_POINTER
Definition: winerror.h:2365
CComPtr< IShellFolder > m_pDesktop
Definition: CSendToMenu.h:65

Referenced by CSendToMenu(), and LoadAllItems().

◆ GetUIObjectFromPidl()

HRESULT CSendToMenu::GetUIObjectFromPidl ( HWND  hwnd,
PIDLIST_ABSOLUTE  pidl,
REFIID  riid,
LPVOID ppvOut 
)
private

Definition at line 129 of file CSendToMenu.cpp.

131 {
132  *ppvOut = NULL;
133 
134  PCITEMID_CHILD pidlLast;
135  CComPtr<IShellFolder> pFolder;
136  HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &pFolder), &pidlLast);
137  if (FAILED_UNEXPECTEDLY(hr))
138  return hr;
139 
140  hr = pFolder->GetUIObjectOf(hwnd, 1, &pidlLast, riid, NULL, ppvOut);
141  if (FAILED_UNEXPECTEDLY(hr))
142  return hr;
143 
144  return hr;
145 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HRESULT hr
Definition: shlfolder.c:183
REFIID riid
Definition: precomp.h:44
#define IID_PPV_ARG(Itype, ppType)
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1323

◆ HandleMenuMsg()

STDMETHODIMP CSendToMenu::HandleMenuMsg ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Implements IContextMenu2.

Definition at line 520 of file CSendToMenu.cpp.

521 {
522  return S_OK;
523 }
#define S_OK
Definition: intsafe.h:59

◆ HandleMenuMsg2()

STDMETHODIMP CSendToMenu::HandleMenuMsg2 ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
LRESULT plResult 
)

Implements IContextMenu3.

Definition at line 526 of file CSendToMenu.cpp.

528 {
529  UINT cxSmall = GetSystemMetrics(SM_CXSMICON);
530  UINT cySmall = GetSystemMetrics(SM_CYSMICON);
531 
532  switch (uMsg)
533  {
534  case WM_MEASUREITEM:
535  {
536  MEASUREITEMSTRUCT* lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
537  if (!lpmis || lpmis->CtlType != ODT_MENU)
538  break;
539 
540  UINT cxMenuCheck = GetSystemMetrics(SM_CXMENUCHECK);
541  if (lpmis->itemWidth < cxMenuCheck)
542  lpmis->itemWidth = cxMenuCheck;
543  if (lpmis->itemHeight < cySmall)
544  lpmis->itemHeight = cySmall;
545 
546  if (plResult)
547  *plResult = TRUE;
548  break;
549  }
550  case WM_DRAWITEM:
551  {
552  DRAWITEMSTRUCT* lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
553  if (!lpdis || lpdis->CtlType != ODT_MENU)
554  break;
555 
556  SENDTO_ITEM *pItem = reinterpret_cast<SENDTO_ITEM *>(lpdis->itemData);
557  HICON hIcon = NULL;
558  if (pItem)
559  hIcon = pItem->hIcon;
560  if (!hIcon)
561  break;
562 
563  const RECT& rcItem = lpdis->rcItem;
564  INT x = 4;
565  INT y = lpdis->rcItem.top;
566  y += (rcItem.bottom - rcItem.top - cySmall) / 2;
567  DrawIconEx(lpdis->hDC, x, y, hIcon, cxSmall, cySmall,
568  0, NULL, DI_NORMAL);
569 
570  if (plResult)
571  *plResult = TRUE;
572  }
573  }
574 
575  return S_OK;
576 }
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
#define ODT_MENU
Definition: winuser.h:2512
#define SM_CXMENUCHECK
Definition: winuser.h:1021
LONG top
Definition: windef.h:307
ULONG_PTR itemData
Definition: winuser.h:3068
#define SM_CYSMICON
Definition: winuser.h:1003
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
int32_t INT
Definition: typedefs.h:57
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:1997
int WINAPI GetSystemMetrics(_In_ int)
#define WM_MEASUREITEM
Definition: winuser.h:1628
#define SM_CXSMICON
Definition: winuser.h:1002
#define DI_NORMAL
Definition: wingdi.h:72
#define S_OK
Definition: intsafe.h:59
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define WM_DRAWITEM
Definition: winuser.h:1627
LONG bottom
Definition: windef.h:309
LPARAM lParam
Definition: combotst.c:139

◆ Initialize()

STDMETHODIMP CSendToMenu::Initialize ( PCIDLIST_ABSOLUTE  pidlFolder,
IDataObject pdtobj,
HKEY  hkeyProgID 
)

Implements IShellExtInit.

Definition at line 579 of file CSendToMenu.cpp.

581 {
582  m_pDataObject = pdtobj;
583  return S_OK;
584 }
CComPtr< IDataObject > m_pDataObject
Definition: CSendToMenu.h:67
#define S_OK
Definition: intsafe.h:59

◆ InsertSendToItems()

UINT CSendToMenu::InsertSendToItems ( HMENU  hMenu,
UINT  idFirst,
UINT  idMenu 
)
private

Definition at line 373 of file CSendToMenu.cpp.

374 {
375  if (m_pItems == NULL)
376  {
378  if (FAILED_UNEXPECTEDLY(hr))
379  return 0;
380  }
381 
382  m_idCmdFirst = idCmdFirst;
383 
384  UINT idCmd = idCmdFirst;
385  for (SENDTO_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
386  {
388  if (InsertMenuW(hMenu, Pos, uFlags, idCmd, pCurItem->pszText))
389  {
390  MENUITEMINFOW mii;
391  mii.cbSize = sizeof(mii);
392  mii.fMask = MIIM_DATA | MIIM_BITMAP;
393  mii.dwItemData = reinterpret_cast<ULONG_PTR>(pCurItem);
394  mii.hbmpItem = HBMMENU_CALLBACK;
395  SetMenuItemInfoW(hMenu, idCmd, FALSE, &mii);
396  ++idCmd;
397 
398  // successful
399  }
400  }
401 
402  if (idCmd == idCmdFirst)
403  {
405  AppendMenuW(hMenu, MF_GRAYED | MF_DISABLED | MF_STRING, idCmd, strNone);
406  }
407 
408  return idCmd - idCmdFirst;
409 }
#define MF_DISABLED
Definition: winuser.h:130
HRESULT hr
Definition: shlfolder.c:183
BOOL WINAPI InsertMenuW(_In_ HMENU, _In_ UINT, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
#define IDS_NONE
Definition: resource.h:122
ush Pos
Definition: deflate.h:92
#define MF_STRING
Definition: winuser.h:138
UINT uFlags
Definition: api.c:59
#define MIIM_BITMAP
Definition: winuser.h:723
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
#define MF_BYPOSITION
Definition: winuser.h:203
BOOL WINAPI SetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
smooth NULL
Definition: ftsmooth.c:416
SENDTO_ITEM * m_pItems
Definition: CSendToMenu.h:62
#define HBMMENU_CALLBACK
Definition: winuser.h:2605
LONG HRESULT
Definition: typedefs.h:78
#define MF_ENABLED
Definition: winuser.h:128
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
HRESULT LoadAllItems(HWND hwnd)
UINT m_idCmdFirst
Definition: CSendToMenu.h:63
unsigned int UINT
Definition: ndis.h:50
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define MF_GRAYED
Definition: winuser.h:129
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3243

Referenced by QueryContextMenu().

◆ InvokeCommand()

STDMETHODIMP CSendToMenu::InvokeCommand ( LPCMINVOKECOMMANDINFO  lpcmi)

Implements IContextMenu.

Definition at line 489 of file CSendToMenu.cpp.

490 {
491  HRESULT hr = E_FAIL;
492 
493  WORD idCmd = LOWORD(lpici->lpVerb);
494  TRACE("idCmd: %d\n", idCmd);
495 
496  SENDTO_ITEM *pItem = FindItemFromIdOffset(idCmd);
497  if (pItem)
498  {
499  hr = DoSendToItem(pItem, lpici);
500  }
501 
502  TRACE("CSendToMenu::InvokeCommand %x\n", hr);
503  return hr;
504 }
HRESULT hr
Definition: shlfolder.c:183
#define E_FAIL
Definition: ddrawi.h:102
SENDTO_ITEM * FindItemFromIdOffset(UINT IdOffset)
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:78
unsigned short WORD
Definition: ntddk_ex.h:93
HRESULT DoSendToItem(SENDTO_ITEM *pItem, LPCMINVOKECOMMANDINFO lpici)
#define LOWORD(l)
Definition: pedump.c:82

◆ LoadAllItems()

HRESULT CSendToMenu::LoadAllItems ( HWND  hwnd)
private

Definition at line 311 of file CSendToMenu.cpp.

312 {
313  UnloadAllItems();
314 
315  if (!FolderHasAnyItems())
316  {
320  }
321 
323 
324  m_pSendTo.Release();
326  if (FAILED_UNEXPECTEDLY(hr))
327  return hr;
328 
329  CComPtr<IEnumIDList> pEnumIDList;
330  hr = m_pSendTo->EnumObjects(hwnd,
331  SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,
332  &pEnumIDList);
333  if (FAILED_UNEXPECTEDLY(hr))
334  return hr;
335 
336  hr = S_OK;
338  while (pEnumIDList->Next(1, &child, NULL) == S_OK)
339  {
340  CComHeapPtr<ITEMID_CHILD> pidlChild(child);
341 
342  STRRET strret;
343  hr = m_pSendTo->GetDisplayNameOf(pidlChild, SHGDN_NORMAL, &strret);
344  if (FAILED_UNEXPECTEDLY(hr))
345  continue;
346 
347  CComHeapPtr<WCHAR> pszText;
348  hr = StrRetToStrW(&strret, pidlChild, &pszText);
349  if (FAILED_UNEXPECTEDLY(hr))
350  continue;
351 
353  pidlAbsolute.Attach(ILCombine(pidlSendTo, pidlChild));
354 
355  SHFILEINFOW fi = { NULL };
358  SHGetFileInfoW(reinterpret_cast<LPWSTR>(static_cast<PIDLIST_ABSOLUTE>(pidlAbsolute)), 0,
359  &fi, sizeof(fi), uFlags);
360 
361  SENDTO_ITEM *pNewItem =
362  new SENDTO_ITEM(pidlChild.Detach(), pszText.Detach(), fi.hIcon);
363  if (m_pItems)
364  {
365  pNewItem->pNext = m_pItems;
366  }
367  m_pItems = pNewItem;
368  }
369 
370  return hr;
371 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define SHGFI_TYPENAME
Definition: shellapi.h:165
HRESULT hr
Definition: shlfolder.c:183
CComPtr< IShellFolder > m_pSendTo
Definition: CSendToMenu.h:66
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
UINT uFlags
Definition: api.c:59
#define SHGFI_SMALLICON
Definition: shellapi.h:174
static HWND child
Definition: cursoricon.c:298
#define SHGFI_PIDL
Definition: shellapi.h:178
smooth NULL
Definition: ftsmooth.c:416
SENDTO_ITEM * m_pItems
Definition: CSendToMenu.h:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:413
LONG HRESULT
Definition: typedefs.h:78
#define CSIDL_SENDTO
Definition: shlobj.h:2020
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
BOOL FolderHasAnyItems() const
HRESULT CreateSendToFiles(LPCWSTR pszSendTo)
HICON hIcon
Definition: shellapi.h:370
#define S_OK
Definition: intsafe.h:59
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2685
LPCWSTR szPath
Definition: env.c:35
void Release()
Definition: atlcomcli.h:140
void UnloadAllItems()
unsigned int UINT
Definition: ndis.h:50
#define SHGFI_ICON
Definition: shellapi.h:162
HRESULT GetSpecialFolder(HWND hwnd, IShellFolder **ppFolder, int csidl, PIDLIST_ABSOLUTE *ppidl=NULL)
HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *ppszName)
Definition: string.c:1623

Referenced by InsertSendToItems().

◆ QueryContextMenu()

STDMETHODIMP CSendToMenu::QueryContextMenu ( HMENU  hMenu,
UINT  indexMenu,
UINT  idCmdFirst,
UINT  idCmdLast,
UINT  uFlags 
)

Implements IContextMenu.

Definition at line 447 of file CSendToMenu.cpp.

452 {
453  TRACE("%p %p %u %u %u %u\n", this,
454  hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
455 
456  HMENU hSubMenu = CreateMenu();
457  if (!hSubMenu)
458  {
459  ERR("CreateMenu: %ld\n", GetLastError());
460  return E_FAIL;
461  }
462 
463  UINT cItems = InsertSendToItems(hSubMenu, idCmdFirst, 0);
464 
466 
467  MENUITEMINFOW mii = { sizeof(mii) };
469  mii.fType = MFT_STRING;
470  mii.wID = -1;
471  mii.dwTypeData = strSendTo.GetBuffer();
472  mii.cch = wcslen(mii.dwTypeData);
473  mii.fState = MFS_ENABLED;
474  mii.hSubMenu = hSubMenu;
475  if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
476  {
477  ERR("InsertMenuItemW: %ld\n", GetLastError());
478  return E_FAIL;
479  }
480 
481  HMENU hOldSubMenu = m_hSubMenu;
482  m_hSubMenu = hSubMenu;
483  DestroyMenu(hOldSubMenu);
484 
485  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cItems);
486 }
HMENU WINAPI CreateMenu(void)
Definition: menu.c:837
#define MFT_STRING
Definition: winuser.h:741
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPWSTR dwTypeData
Definition: winuser.h:3244
UINT uFlags
Definition: api.c:59
#define E_FAIL
Definition: ddrawi.h:102
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define MIIM_SUBMENU
Definition: winuser.h:718
#define MFS_ENABLED
Definition: winuser.h:745
#define MIIM_STATE
Definition: winuser.h:716
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define MIIM_ID
Definition: winuser.h:717
#define TRACE(s)
Definition: solgame.cpp:4
UINT InsertSendToItems(HMENU hMenu, UINT idFirst, UINT idMenu)
HMENU m_hSubMenu
Definition: CSendToMenu.h:61
#define MIIM_TYPE
Definition: winuser.h:720
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define ERR(fmt,...)
Definition: debug.h:109
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
#define IDS_SENDTO_MENU
Definition: shresdef.h:233
unsigned int UINT
Definition: ndis.h:50
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ UnloadAllItems()

void CSendToMenu::UnloadAllItems ( )
private

Definition at line 147 of file CSendToMenu.cpp.

148 {
149  SENDTO_ITEM *pItems = m_pItems;
150  m_pItems = NULL;
151  while (pItems)
152  {
153  SENDTO_ITEM *pCurItem = pItems;
154  pItems = pItems->pNext;
155  delete pCurItem;
156  }
157 }
smooth NULL
Definition: ftsmooth.c:416
SENDTO_ITEM * m_pItems
Definition: CSendToMenu.h:62
static int int const SCRIPT_CONTROL const SCRIPT_STATE SCRIPT_ITEM * pItems
Definition: usp10.c:62

Referenced by LoadAllItems(), and ~CSendToMenu().

Member Data Documentation

◆ m_hSubMenu

HMENU CSendToMenu::m_hSubMenu
private

Definition at line 61 of file CSendToMenu.h.

Referenced by FindItemFromIdOffset(), QueryContextMenu(), and ~CSendToMenu().

◆ m_idCmdFirst

UINT CSendToMenu::m_idCmdFirst
private

Definition at line 63 of file CSendToMenu.h.

Referenced by FindItemFromIdOffset(), and InsertSendToItems().

◆ m_pDataObject

CComPtr<IDataObject> CSendToMenu::m_pDataObject
private

Definition at line 67 of file CSendToMenu.h.

Referenced by DoSendToItem(), and Initialize().

◆ m_pDesktop

CComPtr<IShellFolder> CSendToMenu::m_pDesktop
private

Definition at line 65 of file CSendToMenu.h.

Referenced by CSendToMenu(), and GetSpecialFolder().

◆ m_pItems

SENDTO_ITEM* CSendToMenu::m_pItems
private

Definition at line 62 of file CSendToMenu.h.

Referenced by InsertSendToItems(), LoadAllItems(), and UnloadAllItems().

◆ m_pSendTo

CComPtr<IShellFolder> CSendToMenu::m_pSendTo
private

Definition at line 66 of file CSendToMenu.h.

Referenced by CSendToMenu(), DoSendToItem(), and LoadAllItems().


The documentation for this class was generated from the following files: