[EXPLORER] -Fix a parameter of OnCreateTaskbarPage(). Fix by Mark Jansen
[reactos.git] / reactos / base / shell / explorer / startmnu.cpp
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 HRESULT
24 UpdateStartMenu(IN OUT IMenuPopup *pMenuPopup,
25 IN HBITMAP hbmBanner OPTIONAL,
26 IN BOOL bSmallIcons)
27 {
28 CComPtr<IBanneredBar> pbb;
29 HRESULT hRet;
30
31 hRet = pMenuPopup->QueryInterface(IID_PPV_ARG(IBanneredBar, &pbb));
32 if (SUCCEEDED(hRet))
33 {
34 hRet = pbb->SetBitmap(hbmBanner);
35
36 /* Update the icon size */
37 hRet = pbb->SetIconSize(bSmallIcons ? BMICON_SMALL : BMICON_LARGE);
38 }
39
40 return hRet;
41 }
42
43 IMenuPopup *
44 CreateStartMenu(IN ITrayWindow *Tray,
45 OUT IMenuBand **ppMenuBand,
46 IN HBITMAP hbmBanner OPTIONAL,
47 IN BOOL bSmallIcons)
48 {
49 HRESULT hr;
50 CComPtr<IMenuPopup> pMp;
51 CComPtr<IUnknown> pSms;
52 CComPtr<IMenuBand> pMb;
53 CComPtr<IInitializeObject> pIo;
54 CComPtr<IUnknown> pUnk;
55 CComPtr<IBandSite> pBs;
56 DWORD dwBandId = 0;
57
58 hr = CreateStartMenuSite(Tray, IID_PPV_ARG(IUnknown, &pSms));
59 if (FAILED_UNEXPECTEDLY(hr))
60 return NULL;
61
62 #if 0
63 hr = CoCreateInstance(&CLSID_StartMenu,
64 NULL,
65 CLSCTX_INPROC_SERVER,
66 &IID_IMenuPopup,
67 (PVOID *)&pMp);
68 #else
69 hr = _CStartMenu_Constructor(IID_PPV_ARG(IMenuPopup, &pMp));
70 #endif
71 if (FAILED_UNEXPECTEDLY(hr))
72 return NULL;
73
74 /* Set the menu site so we can handle messages */
75 hr = IUnknown_SetSite(pMp, pSms);
76 if (FAILED_UNEXPECTEDLY(hr))
77 return NULL;
78
79 /* Initialize the menu object */
80 hr = pMp->QueryInterface(IID_PPV_ARG(IInitializeObject, &pIo));
81 if (SUCCEEDED(hr))
82 hr = pIo->Initialize();
83 else
84 hr = S_OK;
85
86 /* Everything is initialized now. Let's get the IMenuBand interface. */
87 if (FAILED_UNEXPECTEDLY(hr))
88 return NULL;
89
90 hr = pMp->GetClient(&pUnk);
91 if (FAILED_UNEXPECTEDLY(hr))
92 return NULL;
93
94 hr = pUnk->QueryInterface(IID_PPV_ARG(IBandSite, &pBs));
95 if (FAILED_UNEXPECTEDLY(hr))
96 return NULL;
97
98 /* Finally we have the IBandSite interface, there's only one
99 band in it that apparently provides the IMenuBand interface */
100 hr = pBs->EnumBands(0, &dwBandId);
101 if (FAILED_UNEXPECTEDLY(hr))
102 return NULL;
103
104 hr = pBs->GetBandObject(dwBandId, IID_PPV_ARG(IMenuBand, &pMb));
105 if (FAILED_UNEXPECTEDLY(hr))
106 return NULL;
107
108 UpdateStartMenu(pMp,
109 hbmBanner,
110 bSmallIcons);
111
112 *ppMenuBand = pMb.Detach();
113
114 return pMp.Detach();
115 }