ReactOS 0.4.15-dev-8390-g075894b
startctxmnu.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Explorer
3 *
4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "precomp.h"
22
23/*
24 * Start menu button context menu
25 */
26
28 public CComCoClass<CStartMenuBtnCtxMenu>,
29 public CComObjectRootEx<CComMultiThreadModelNoCS>,
30 public IContextMenu
31{
32 /* AddStartContextMenuItems uses ID_SHELL_CMD IDs directly and relies on idCmdFirst being 0.
33 * CTrayWindow::TrackCtxMenu must pass 0 because DeleteMenu ID_SHELL_CMD_UNDO_ACTION would
34 * delete the wrong item if it used 1. m_Inner->QueryContextMenu is not aware of this game
35 * so we have to reserve the entire ID_SHELL_CMD range for ourselves here. */
37 static BOOL IsShellCmdId(UINT_PTR id) { return id < INNERIDOFFSET; }
38
42
45
47 {
48 HRESULT hRet;
49
51 if (SUCCEEDED(hRet))
52 {
53 if (hPopup != NULL)
54 {
55 hRet = m_Inner->QueryContextMenu(
56 hPopup,
57 0,
58 idCmdFirst,
59 idCmdLast,
60 CMF_VERBSONLY);
61
62 if (SUCCEEDED(hRet))
63 {
64 return hRet;
65 }
66 }
67 }
68 return E_FAIL;
69 }
70
72 {
73 WCHAR szBuf[MAX_PATH];
74 HRESULT hRet;
76 /* If this ever asserts, let m_Inner use 1..ID_SHELL_CMD_FIRST-1 instead */
77 C_ASSERT(ID_SHELL_CMD_LAST < 0xffff / 2);
78
79 /* Add the "Open All Users" menu item */
82 szBuf,
83 _countof(szBuf)))
84 {
85 AppendMenu(hPopup,
88 szBuf);
89 }
90
92 {
93 /* Check if we should add menu items for the common start menu */
96 NULL,
98 szBuf);
99 if (SUCCEEDED(hRet) && hRet != S_FALSE)
100 {
101 /* The directory exists, but only show the items if the
102 user can actually make any changes to the common start
103 menu. This is most likely only the case if the user
104 has administrative rights! */
105 if (IsUserAnAdmin())
106 {
107 AppendMenu(hPopup,
109 0,
110 NULL);
111
112 /* Add the "Open All Users" menu item */
115 szBuf,
116 _countof(szBuf)))
117 {
118 AppendMenu(hPopup,
119 MF_STRING,
121 szBuf);
122 }
123
124 /* Add the "Explore All Users" menu item */
127 szBuf,
128 _countof(szBuf)))
129 {
130 AppendMenu(hPopup,
131 MF_STRING,
133 szBuf);
134 }
135 }
136 }
137 }
138 }
139
140public:
141 HRESULT Initialize(ITrayWindow * pTrayWnd, IN HWND hWndOwner)
142 {
143 m_TrayWnd = pTrayWnd;
144 m_Owner = hWndOwner;
145 return S_OK;
146 }
147
150 UINT indexMenu,
151 UINT idCmdFirst,
152 UINT idCmdLast,
153 UINT uFlags)
154 {
155 LPITEMIDLIST pidlStart;
156 CComPtr<IShellFolder> psfDesktop;
157 HRESULT hRet = S_OK;
158 UINT idInnerFirst = idCmdFirst + INNERIDOFFSET;
159
160 psfDesktop = NULL;
161 m_Inner = NULL;
162
164 if (pidlStart != NULL)
165 {
166 m_FolderPidl = ILClone(ILFindLastID(pidlStart));
167 ILRemoveLastID(pidlStart);
168
169 if (m_FolderPidl != NULL)
170 {
171 hRet = SHGetDesktopFolder(&psfDesktop);
172 if (SUCCEEDED(hRet))
173 {
174 hRet = psfDesktop->BindToObject(pidlStart, NULL, IID_PPV_ARG(IShellFolder, &m_Folder));
175 if (SUCCEEDED(hRet))
176 {
177 hRet = CreateContextMenuFromShellFolderPidl(hPopup, idInnerFirst, idCmdLast);
178 }
179 }
180 }
181
182 ILFree(pidlStart);
183 }
184 if (idCmdLast - idCmdFirst >= ID_SHELL_CMD_LAST - ID_SHELL_CMD_FIRST)
185 {
187 hRet = SUCCEEDED(hRet) ? hRet + idInnerFirst : idInnerFirst;
188 }
189 return hRet;
190 }
191
194 {
195 UINT uiCmdId = PtrToUlong(lpici->lpVerb);
196 if (!IsShellCmdId((UINT_PTR)lpici->lpVerb))
197 {
198 CMINVOKECOMMANDINFO cmici = { 0 };
199 CHAR szDir[MAX_PATH];
200
201 /* Setup and invoke the shell command */
202 cmici.cbSize = sizeof(cmici);
203 cmici.hwnd = m_Owner;
204 if (IS_INTRESOURCE(lpici->lpVerb))
205 cmici.lpVerb = MAKEINTRESOURCEA(uiCmdId - INNERIDOFFSET);
206 else
207 cmici.lpVerb = lpici->lpVerb;
208 cmici.nShow = SW_NORMAL;
209
210 /* FIXME: Support Unicode!!! */
212 {
213 cmici.lpDirectory = szDir;
214 }
215
216 return m_Inner->InvokeCommand(&cmici);
217 }
218 m_TrayWnd->ExecContextMenuCmd(uiCmdId);
219 return S_OK;
220 }
221
224 UINT uType,
225 UINT *pwReserved,
226 LPSTR pszName,
227 UINT cchMax)
228 {
229 if (!IsShellCmdId(idCmd) && m_Inner)
230 return m_Inner->GetCommandString(idCmd, uType, pwReserved, pszName, cchMax);
231 return E_NOTIMPL;
232 }
233
235 {
236 }
237
239 {
240 if (m_FolderPidl)
242 }
243
245 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
247};
248
249HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu)
250{
251 return ShellObjectCreatorInit<CStartMenuBtnCtxMenu>(m_TrayWnd, m_Owner, IID_PPV_ARG(IContextMenu, ppCtxMenu));
252}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
UINT cchMax
HINSTANCE hExplorerInstance
Definition: explorer.cpp:24
#define IDS_PROPERTIES
Definition: resource.h:102
#define ID_SHELL_CMD_PROPERTIES
Definition: resource.h:204
#define ID_SHELL_CMD_FIRST
Definition: resource.h:217
#define IDS_EXPLORE_ALL_USERS
Definition: resource.h:101
#define ID_SHELL_CMD_EXPLORE_ALL_USERS
Definition: resource.h:206
#define IDS_OPEN_ALL_USERS
Definition: resource.h:100
#define ID_SHELL_CMD_OPEN_ALL_USERS
Definition: resource.h:205
#define ID_SHELL_CMD_LAST
Definition: resource.h:218
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
LPITEMIDLIST m_FolderPidl
Definition: startctxmnu.cpp:44
HRESULT CreateContextMenuFromShellFolderPidl(HMENU hPopup, UINT idCmdFirst, UINT idCmdLast)
Definition: startctxmnu.cpp:46
virtual HRESULT STDMETHODCALLTYPE InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
CComPtr< IShellFolder > m_Folder
Definition: startctxmnu.cpp:41
virtual HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax)
CComPtr< IContextMenu > m_Inner
Definition: startctxmnu.cpp:40
CComPtr< ITrayWindow > m_TrayWnd
Definition: startctxmnu.cpp:39
VOID AddStartContextMenuItems(IN HMENU hPopup)
Definition: startctxmnu.cpp:71
HRESULT Initialize(ITrayWindow *pTrayWnd, IN HWND hWndOwner)
virtual HRESULT STDMETHODCALLTYPE QueryContextMenu(HMENU hPopup, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
virtual ~CStartMenuBtnCtxMenu()
static BOOL IsShellCmdId(UINT_PTR id)
Definition: startctxmnu.cpp:37
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
UINT uFlags
Definition: api.c:59
#define MAX_PATH
Definition: compat.h:34
#define PtrToUlong(u)
Definition: config.h:107
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define C_ASSERT(e)
Definition: intsafe.h:73
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define END_COM_MAP()
Definition: atlcom.h:592
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, int nFolder, BOOL fCreate)
Definition: pidl.c:443
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:940
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:198
BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
Definition: pidl.c:1280
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:221
#define SHGetFolderPath
Definition: shlobj.h:2170
#define CSIDL_COMMON_STARTMENU
Definition: shlobj.h:2193
@ SHGFP_TYPE_CURRENT
Definition: shlobj.h:2148
BOOL WINAPI IsUserAnAdmin(void)
Definition: shellord.c:2797
#define CSIDL_STARTMENU
Definition: shlobj.h:2183
@ REST_NOCOMMONGROUPS
Definition: shlobj.h:1664
DWORD WINAPI SHRestricted(RESTRICTIONS rest)
Definition: shpolicy.c:150
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:70
HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow *m_TrayWnd, IN HWND m_Owner, IContextMenu **ppCtxMenu)
#define IN
Definition: typedefs.h:39
#define S_FALSE
Definition: winerror.h:2357
#define AppendMenu
Definition: winuser.h:5740
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
#define MF_STRING
Definition: winuser.h:138
#define MF_SEPARATOR
Definition: winuser.h:137
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
#define SW_NORMAL
Definition: winuser.h:769
#define IID_PPV_ARG(Itype, ppType)
#define IID_NULL_PPV_ARG(Itype, ppType)
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175