ReactOS 0.4.15-dev-7788-g1ad9096
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{
36
39
41 {
42 HRESULT hRet;
43
45 if (SUCCEEDED(hRet))
46 {
47 if (hPopup != NULL)
48 {
49 hRet = m_Inner->QueryContextMenu(
50 hPopup,
51 0,
54 CMF_VERBSONLY);
55
56 if (SUCCEEDED(hRet))
57 {
58 return hRet;
59 }
60
61 DestroyMenu(hPopup);
62 }
63 }
64
65 return E_FAIL;
66 }
67
69 {
70 WCHAR szBuf[MAX_PATH];
71 HRESULT hRet;
72
73 /* Add the "Open All Users" menu item */
76 szBuf,
77 _countof(szBuf)))
78 {
79 AppendMenu(hPopup,
82 szBuf);
83 }
84
86 {
87 /* Check if we should add menu items for the common start menu */
90 NULL,
92 szBuf);
93 if (SUCCEEDED(hRet) && hRet != S_FALSE)
94 {
95 /* The directory exists, but only show the items if the
96 user can actually make any changes to the common start
97 menu. This is most likely only the case if the user
98 has administrative rights! */
99 if (IsUserAnAdmin())
100 {
101 AppendMenu(hPopup,
103 0,
104 NULL);
105
106 /* Add the "Open All Users" menu item */
109 szBuf,
110 _countof(szBuf)))
111 {
112 AppendMenu(hPopup,
113 MF_STRING,
115 szBuf);
116 }
117
118 /* Add the "Explore All Users" menu item */
121 szBuf,
122 _countof(szBuf)))
123 {
124 AppendMenu(hPopup,
125 MF_STRING,
127 szBuf);
128 }
129 }
130 }
131 }
132 }
133
134public:
135 HRESULT Initialize(ITrayWindow * pTrayWnd, IN HWND hWndOwner)
136 {
137 m_TrayWnd = pTrayWnd;
138 m_Owner = hWndOwner;
139 return S_OK;
140 }
141
144 UINT indexMenu,
145 UINT idCmdFirst,
146 UINT idCmdLast,
147 UINT uFlags)
148 {
149 LPITEMIDLIST pidlStart;
150 CComPtr<IShellFolder> psfDesktop;
151 HRESULT hRet;
152
153 psfDesktop = NULL;
154 m_Inner = NULL;
155
157
158 if (pidlStart != NULL)
159 {
160 m_FolderPidl = ILClone(ILFindLastID(pidlStart));
161 ILRemoveLastID(pidlStart);
162
163 if (m_FolderPidl != NULL)
164 {
165 hRet = SHGetDesktopFolder(&psfDesktop);
166 if (SUCCEEDED(hRet))
167 {
168 hRet = psfDesktop->BindToObject(pidlStart, NULL, IID_PPV_ARG(IShellFolder, &m_Folder));
169 if (SUCCEEDED(hRet))
170 {
174 }
175 }
176 }
177
178 ILFree(pidlStart);
179 }
180
181 return S_OK;
182 }
183
186 {
187 UINT uiCmdId = PtrToUlong(lpici->lpVerb);
188 if (uiCmdId != 0)
189 {
190 if ((uiCmdId >= ID_SHELL_CMD_FIRST) && (uiCmdId < m_idCmdCmLast))
191 {
192 CMINVOKECOMMANDINFO cmici = { 0 };
193 CHAR szDir[MAX_PATH];
194
195 /* Setup and invoke the shell command */
196 cmici.cbSize = sizeof(cmici);
197 cmici.hwnd = m_Owner;
198 cmici.lpVerb = MAKEINTRESOURCEA(uiCmdId - ID_SHELL_CMD_FIRST);
199 cmici.nShow = SW_NORMAL;
200
201 /* FIXME: Support Unicode!!! */
203 {
204 cmici.lpDirectory = szDir;
205 }
206
207 m_Inner->InvokeCommand(&cmici);
208 }
209 else
210 {
211 m_TrayWnd->ExecContextMenuCmd(uiCmdId);
212 }
213 }
214 return S_OK;
215 }
216
219 UINT uType,
220 UINT *pwReserved,
221 LPSTR pszName,
222 UINT cchMax)
223 {
224 return E_NOTIMPL;
225 }
226
228 {
230 }
231
233 {
234 if (m_FolderPidl)
236 }
237
239 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
241};
242
243HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu)
244{
245 return ShellObjectCreatorInit<CStartMenuBtnCtxMenu>(m_TrayWnd, m_Owner, IID_PPV_ARG(IContextMenu, ppCtxMenu));
246}
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:205
#define ID_SHELL_CMD_FIRST
Definition: resource.h:203
#define IDS_EXPLORE_ALL_USERS
Definition: resource.h:101
#define ID_SHELL_CMD_EXPLORE_ALL_USERS
Definition: resource.h:207
#define IDS_OPEN_ALL_USERS
Definition: resource.h:100
#define ID_SHELL_CMD_OPEN_ALL_USERS
Definition: resource.h:206
#define ID_SHELL_CMD_LAST
Definition: resource.h:204
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
LPITEMIDLIST m_FolderPidl
Definition: startctxmnu.cpp:38
virtual HRESULT STDMETHODCALLTYPE InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
CComPtr< IShellFolder > m_Folder
Definition: startctxmnu.cpp:34
virtual HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax)
CComPtr< IContextMenu > m_Inner
Definition: startctxmnu.cpp:33
CComPtr< ITrayWindow > m_TrayWnd
Definition: startctxmnu.cpp:32
VOID AddStartContextMenuItems(IN HMENU hPopup)
Definition: startctxmnu.cpp:68
HRESULT Initialize(ITrayWindow *pTrayWnd, IN HWND hWndOwner)
virtual HRESULT STDMETHODCALLTYPE QueryContextMenu(HMENU hPopup, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
virtual ~CStartMenuBtnCtxMenu()
HRESULT CreateContextMenuFromShellFolderPidl(HMENU hPopup)
Definition: startctxmnu.cpp:40
#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
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#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:434
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:929
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
Definition: pidl.c:1282
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:212
#define SHGetFolderPath
Definition: shlobj.h:2156
#define CSIDL_COMMON_STARTMENU
Definition: shlobj.h:2179
@ SHGFP_TYPE_CURRENT
Definition: shlobj.h:2134
BOOL WINAPI IsUserAnAdmin(void)
Definition: shellord.c:2579
#define CSIDL_STARTMENU
Definition: shlobj.h:2169
@ REST_NOCOMMONGROUPS
Definition: shlobj.h:1650
DWORD WINAPI SHRestricted(RESTRICTIONS rest)
Definition: shpolicy.c:146
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:68
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 HRESULT_CODE(hr)
Definition: winerror.h:76
#define AppendMenu
Definition: winuser.h:5731
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MF_STRING
Definition: winuser.h:138
#define MF_SEPARATOR
Definition: winuser.h:137
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI DestroyMenu(_In_ HMENU)
#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