ReactOS 0.4.15-dev-7924-g5949c20
startmnusite.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
24 public CComCoClass<CStartMenuSite>,
25 public CComObjectRootEx<CComMultiThreadModelNoCS>,
26 public IServiceProvider,
27 public ITrayPriv,
28 public IOleCommandTarget,
29 public IMenuPopup
30{
32
33public:
35 {
36 }
37
38 virtual ~CStartMenuSite() {}
39
40 /*******************************************************************/
41
43 IN REFGUID guidService,
46 {
47 if (IsEqualGUID(guidService, SID_SMenuPopup))
48 {
50 }
51
52 return E_NOINTERFACE;
53 }
54
55 /*******************************************************************/
56
58 OUT HWND *phwnd)
59 {
60 TRACE("ITrayPriv::GetWindow\n");
61
62 *phwnd = m_Tray->GetHWND();
63 if (*phwnd != NULL)
64 return S_OK;
65
66 return E_FAIL;
67 }
68
70 IN BOOL fEnterMode)
71 {
72 TRACE("ITrayPriv::ContextSensitiveHelp\n");
73 return E_NOTIMPL;
74 }
75
77 IN IShellFolder *pShellFolder,
78 IN LPCITEMIDLIST pidl)
79 {
81
82 TRACE("ITrayPriv::Execute\n");
83
84 ret = SHInvokeDefaultCommand(m_Tray->GetHWND(), pShellFolder, pidl);
85
86 return ret;
87 }
88
90 IN PVOID Unknown1,
91 IN PVOID Unknown2,
94 {
95 TRACE("ITrayPriv::Unknown(0x%p,0x%p,0x%p,0x%p)\n", Unknown1, Unknown2, Unknown3, Unknown4);
96 return E_NOTIMPL;
97 }
98
99 virtual BOOL
101 {
102 TRACE("ShowUndockMenuItem() not implemented!\n");
103 /* FIXME: How do we detect this?! */
104 return FALSE;
105 }
106
107 virtual BOOL
109 {
110 TRACE("ShowSynchronizeMenuItem() not implemented!\n");
111 /* FIXME: How do we detect this?! */
112 return FALSE;
113 }
114
116 OUT HMENU* phMenu)
117 {
118 HMENU hMenu, hSettingsMenu;
119 DWORD dwLogoff;
120 BOOL bWantLogoff;
121 UINT uLastItemsCount = 5; /* 5 menu items below the last separator */
122 WCHAR szUser[128];
123
124 TRACE("ITrayPriv::AppendMenu\n");
125
127 *phMenu = hMenu;
128 if (hMenu == NULL)
129 return E_FAIL;
130
131 /* Remove menu items that don't apply */
132
133 /* Favorites */
135 !GetAdvancedBool(L"StartMenuFavorites", FALSE))
136 {
138 }
139
140 /* Documents */
142 !GetAdvancedBool(L"Start_ShowRecentDocs", TRUE))
143 {
145 }
146
147 /* Settings */
148 hSettingsMenu = FindSubMenu(hMenu, IDM_SETTINGS, FALSE);
149
150 /* Control Panel */
153 !GetAdvancedBool(L"Start_ShowControlPanel", TRUE))
154 {
156
157 /* Delete the separator below it */
158 DeleteMenu(hSettingsMenu, 0, MF_BYPOSITION);
159 }
160
161 /* Network Connections */
164 !GetAdvancedBool(L"Start_ShowNetConn", TRUE))
165 {
167 }
168
169 /* Printers and Faxes */
171 !GetAdvancedBool(L"Start_ShowPrinters", TRUE))
172 {
174 }
175
176 /* Security */
178 GetSystemMetrics(SM_REMOTECONTROL) == 0 ||
180 {
181 DeleteMenu(hSettingsMenu, IDM_SECURITY, MF_BYCOMMAND);
182 }
183
184 /* Delete Settings menu if it was empty */
185 if (GetMenuItemCount(hSettingsMenu) == 0)
186 {
188 }
189
190 /* Search */
192 !GetAdvancedBool(L"Start_ShowSearch", TRUE))
193 {
195 }
196
197 /* Help */
199 !GetAdvancedBool(L"Start_ShowHelp", TRUE))
200 {
202 }
203
204 /* Run */
206 !GetAdvancedBool(L"StartMenuRun", TRUE))
207 {
209 }
210
211 /* Synchronize */
213 {
215 uLastItemsCount--;
216 }
217
218 /* Log off */
220 bWantLogoff = (dwLogoff == 2 ||
222 GetAdvancedBool(L"StartMenuLogoff", FALSE));
223 if (dwLogoff != 1 && bWantLogoff)
224 {
225 /* FIXME: We need a more sophisticated way to determine whether to show
226 or hide it, it might be hidden in too many cases!!! */
227
228 /* Update Log Off menu item */
229 if (!GetCurrentLoggedOnUserName(szUser, _countof(szUser)))
230 {
231 szUser[0] = _T('\0');
232 }
233
234 if (!FormatMenuString(hMenu,
237 szUser))
238 {
239 /* We couldn't update the menu item, delete it... */
241 }
242 }
243 else
244 {
246 uLastItemsCount--;
247 }
248
249 /* Disconnect */
251 GetSystemMetrics(SM_REMOTECONTROL) == 0)
252 {
254 uLastItemsCount--;
255 }
256
257 /* Undock computer */
258 if (!ShowUndockMenuItem())
259 {
261 uLastItemsCount--;
262 }
263
264 /* Shut down */
266 {
268 uLastItemsCount--;
269 }
270
271 if (uLastItemsCount == 0)
272 {
273 /* Remove the separator at the end of the menu */
275 }
276
277 return S_OK;
278 }
279
280 /*******************************************************************/
281
283 IN const GUID *pguidCmdGroup OPTIONAL,
284 IN ULONG cCmds,
285 IN OUT OLECMD *prgCmds,
286 IN OUT OLECMDTEXT *pCmdText OPTIONAL)
287 {
288 return E_NOTIMPL;
289 }
290
292 IN const GUID *pguidCmdGroup OPTIONAL,
293 IN DWORD nCmdID,
294 IN DWORD nCmdExecOpt,
295 IN VARIANTARG *pvaIn OPTIONAL,
296 IN VARIANTARG *pvaOut OPTIONAL)
297 {
298 return E_NOTIMPL;
299 }
300
301 /*******************************************************************/
302
304 {
305 return E_NOTIMPL;
306 }
307
309 {
310 return E_NOTIMPL;
311 }
312
314 {
315 return E_NOTIMPL;
316 }
317
319 {
320 return E_NOTIMPL;
321 }
322
324 {
325 return E_NOTIMPL;
326 }
327
329 {
330 if (!fSet)
331 {
333 }
334
335 return S_OK;
336 }
337
338 /*******************************************************************/
339
340 HRESULT Initialize(IN ITrayWindow *tray)
341 {
342 m_Tray = tray;
343 return S_OK;
344 }
345
347
350 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
351 COM_INTERFACE_ENTRY_IID(IID_ITrayPriv, ITrayPriv)
352 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
353 COM_INTERFACE_ENTRY_IID(IID_IMenuPopup, IMenuPopup)
356};
357
359{
360 return ShellObjectCreatorInit<CStartMenuSite>(Tray, riid, ppv);
361}
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
HINSTANCE hExplorerInstance
Definition: explorer.cpp:24
HMENU FindSubMenu(IN HMENU hMenu, IN UINT uItem, IN BOOL fByPosition)
Definition: util.cpp:55
BOOL FormatMenuString(IN HMENU hMenu, IN UINT uPosition, IN UINT uFlags,...)
Definition: util.cpp:106
BOOL GetAdvancedBool(IN LPCWSTR pszValueName, IN BOOL bDefaultValue)
Definition: util.cpp:156
HMENU LoadPopupMenu(IN HINSTANCE hInstance, IN LPCWSTR lpMenuName)
Definition: util.cpp:33
HRESULT Tray_OnStartMenuDismissed(ITrayWindow *Tray)
Definition: traywnd.cpp:3893
BOOL GetCurrentLoggedOnUserName(OUT LPWSTR szBuffer, IN DWORD dwBufferSize)
Definition: util.cpp:73
#define IDM_SEARCH
Definition: resource.h:71
#define IDM_FAVORITES
Definition: resource.h:63
#define IDM_UNDOCKCOMPUTER
Definition: resource.h:77
#define IDM_SECURITY
Definition: resource.h:67
#define IDM_SYNCHRONIZE
Definition: resource.h:74
#define IDM_NETWORKCONNECTIONS
Definition: resource.h:68
#define IDM_SHUTDOWN
Definition: resource.h:78
#define IDM_CONTROLPANEL
Definition: resource.h:66
#define IDM_PRINTERSANDFAXES
Definition: resource.h:69
#define IDM_LASTSTARTMENU_SEPARATOR
Definition: resource.h:79
#define IDM_SETTINGS
Definition: resource.h:65
#define IDM_DISCONNECT
Definition: resource.h:76
#define IDM_RUN
Definition: resource.h:73
#define IDM_STARTMENU
Definition: resource.h:56
#define IDM_HELPANDSUPPORT
Definition: resource.h:72
#define IDM_DOCUMENTS
Definition: resource.h:64
#define IDM_LOGOFF
Definition: resource.h:75
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
virtual HRESULT STDMETHODCALLTYPE Popup(POINTL *ppt, RECTL *prcExclude, MP_POPUPFLAGS dwFlags)
virtual ~CStartMenuSite()
virtual BOOL ShowSynchronizeMenuItem(VOID)
virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(IN BOOL fEnterMode)
CComPtr< ITrayWindow > m_Tray
virtual BOOL ShowUndockMenuItem(VOID)
virtual HRESULT STDMETHODCALLTYPE Unknown(IN PVOID Unknown1, IN PVOID Unknown2, IN PVOID Unknown3, IN PVOID Unknown4)
virtual HRESULT STDMETHODCALLTYPE AppendMenu(OUT HMENU *phMenu)
virtual HRESULT STDMETHODCALLTYPE QueryStatus(IN const GUID *pguidCmdGroup OPTIONAL, IN ULONG cCmds, IN OUT OLECMD *prgCmds, IN OUT OLECMDTEXT *pCmdText OPTIONAL)
HRESULT Initialize(IN ITrayWindow *tray)
virtual HRESULT STDMETHODCALLTYPE OnSelect(DWORD dwSelectType)
virtual HRESULT STDMETHODCALLTYPE Exec(IN const GUID *pguidCmdGroup OPTIONAL, IN DWORD nCmdID, IN DWORD nCmdExecOpt, IN VARIANTARG *pvaIn OPTIONAL, IN VARIANTARG *pvaOut OPTIONAL)
virtual HRESULT STDMETHODCALLTYPE SetClient(IUnknown *punkClient)
virtual HRESULT STDMETHODCALLTYPE GetClient(IUnknown **ppunkClient)
virtual HRESULT STDMETHODCALLTYPE SetSubMenu(IMenuPopup *pmp, BOOL fSet)
virtual HRESULT STDMETHODCALLTYPE QueryService(IN REFGUID guidService, IN REFIID riid, OUT PVOID *ppvObject)
virtual HRESULT STDMETHODCALLTYPE OnPosRectChangeDB(RECT *prc)
virtual HRESULT STDMETHODCALLTYPE GetWindow(OUT HWND *phwnd)
virtual HRESULT STDMETHODCALLTYPE Execute(IN IShellFolder *pShellFolder, IN LPCITEMIDLIST pidl)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c: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
#define FALSE
Definition: types.h:117
HRESULT WINAPI SHInvokeDefaultCommand(HWND hWnd, IShellFolder *lpFolder, LPCITEMIDLIST lpApidl)
Definition: ordinal.c:3056
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
int MP_POPUPFLAGS
Definition: shobjidl.idl:2535
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#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 int UINT
Definition: ndis.h:50
_Out_ LPRECT prc
Definition: ntgdi.h:1658
#define L(x)
Definition: ntvdm.h:50
const GUID IID_IOleWindow
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
@ REST_FORCESTARTMENULOGOFF
Definition: shlobj.h:1704
@ REST_NOSETFOLDERS
Definition: shlobj.h:1632
@ REST_NOCONTROLPANEL
Definition: shlobj.h:1693
@ REST_STARTMENULOGOFF
Definition: shlobj.h:1656
@ REST_NONETWORKCONNECTIONS
Definition: shlobj.h:1703
@ REST_NOSECURITY
Definition: shlobj.h:1852
@ REST_NORECENTDOCSMENU
Definition: shlobj.h:1660
@ REST_NORUN
Definition: shlobj.h:1628
@ REST_NOFIND
Definition: shlobj.h:1635
@ REST_NODISCONNECT
Definition: shlobj.h:1851
@ REST_NOSMHELP
Definition: shlobj.h:1725
@ REST_NOCLOSE
Definition: shlobj.h:1629
@ REST_NOFAVORITESMENU
Definition: shlobj.h:1663
DWORD WINAPI SHRestricted(RESTRICTIONS rest)
Definition: shpolicy.c:146
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:68
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT CStartMenuSite_CreateInstance(IN OUT ITrayWindow *Tray, const IID &riid, PVOID *ppv)
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
Definition: scsiwmi.h:51
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define _T(x)
Definition: vfdio.h:22
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
#define MF_BYCOMMAND
Definition: winuser.h:202
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
BOOL WINAPI DeleteMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_BYPOSITION
Definition: winuser.h:203
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
int WINAPI GetSystemMetrics(_In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define const
Definition: zconf.h:233