4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
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.
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.
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
24 * Start menu button context menu
27 class CStartMenuBtnCtxMenu
:
28 public CComCoClass
<CStartMenuBtnCtxMenu
>,
29 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
32 CComPtr
<ITrayWindow
> m_TrayWnd
;
33 CComPtr
<IContextMenu
> m_Inner
;
34 CComPtr
<IShellFolder
> m_Folder
;
37 LPITEMIDLIST m_FolderPidl
;
39 HRESULT
CreateContextMenuFromShellFolderPidl(HMENU hPopup
)
43 hRet
= m_Folder
->GetUIObjectOf(m_Owner
, 1, (LPCITEMIDLIST
*) &m_FolderPidl
, IID_NULL_PPV_ARG(IContextMenu
, &m_Inner
));
48 hRet
= m_Inner
->QueryContextMenu(
67 VOID
AddStartContextMenuItems(IN HMENU hPopup
)
69 WCHAR szBuf
[MAX_PATH
];
72 /* Add the "Open All Users" menu item */
73 if (LoadStringW(hExplorerInstance
,
80 ID_SHELL_CMD_PROPERTIES
,
84 if (!SHRestricted(REST_NOCOMMONGROUPS
))
86 /* Check if we should add menu items for the common start menu */
87 hRet
= SHGetFolderPath(m_Owner
,
88 CSIDL_COMMON_STARTMENU
,
92 if (SUCCEEDED(hRet
) && hRet
!= S_FALSE
)
94 /* The directory exists, but only show the items if the
95 user can actually make any changes to the common start
96 menu. This is most likely only the case if the user
97 has administrative rights! */
105 /* Add the "Open All Users" menu item */
106 if (LoadStringW(hExplorerInstance
,
113 ID_SHELL_CMD_OPEN_ALL_USERS
,
117 /* Add the "Explore All Users" menu item */
118 if (LoadStringW(hExplorerInstance
,
119 IDS_EXPLORE_ALL_USERS
,
125 ID_SHELL_CMD_EXPLORE_ALL_USERS
,
134 HRESULT
Initialize(ITrayWindow
* pTrayWnd
, IN HWND hWndOwner
)
136 m_TrayWnd
= pTrayWnd
;
141 virtual HRESULT STDMETHODCALLTYPE
142 QueryContextMenu(HMENU hPopup
,
148 LPITEMIDLIST pidlStart
;
149 CComPtr
<IShellFolder
> psfDesktop
;
155 pidlStart
= SHCloneSpecialIDList(m_Owner
, CSIDL_STARTMENU
, TRUE
);
157 if (pidlStart
!= NULL
)
159 m_FolderPidl
= ILClone(ILFindLastID(pidlStart
));
160 ILRemoveLastID(pidlStart
);
162 if (m_FolderPidl
!= NULL
)
164 hRet
= SHGetDesktopFolder(&psfDesktop
);
167 hRet
= psfDesktop
->BindToObject(pidlStart
, NULL
, IID_PPV_ARG(IShellFolder
, &m_Folder
));
170 CreateContextMenuFromShellFolderPidl(hPopup
);
171 AddStartContextMenuItems(hPopup
);
182 virtual HRESULT STDMETHODCALLTYPE
183 InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
185 UINT uiCmdId
= PtrToUlong(lpici
->lpVerb
);
188 if ((uiCmdId
>= ID_SHELL_CMD_FIRST
) && (uiCmdId
<= ID_SHELL_CMD_LAST
))
190 CMINVOKECOMMANDINFO cmici
= { 0 };
191 CHAR szDir
[MAX_PATH
];
193 /* Setup and invoke the shell command */
194 cmici
.cbSize
= sizeof(cmici
);
195 cmici
.hwnd
= m_Owner
;
196 cmici
.lpVerb
= MAKEINTRESOURCEA(uiCmdId
- ID_SHELL_CMD_FIRST
);
197 cmici
.nShow
= SW_NORMAL
;
199 /* FIXME: Support Unicode!!! */
200 if (SHGetPathFromIDListA(m_FolderPidl
, szDir
))
202 cmici
.lpDirectory
= szDir
;
205 m_Inner
->InvokeCommand(&cmici
);
209 m_TrayWnd
->ExecContextMenuCmd(uiCmdId
);
215 virtual HRESULT STDMETHODCALLTYPE
216 GetCommandString(UINT_PTR idCmd
,
225 CStartMenuBtnCtxMenu()
229 virtual ~CStartMenuBtnCtxMenu()
232 ILFree(m_FolderPidl
);
235 BEGIN_COM_MAP(CStartMenuBtnCtxMenu
)
236 COM_INTERFACE_ENTRY_IID(IID_IContextMenu
, IContextMenu
)
240 HRESULT
StartMenuBtnCtxMenuCreator(ITrayWindow
* m_TrayWnd
, IN HWND m_Owner
, IContextMenu
** ppCtxMenu
)
242 CStartMenuBtnCtxMenu
* mnu
= new CComObject
<CStartMenuBtnCtxMenu
>();
243 mnu
->Initialize(m_TrayWnd
, m_Owner
);