1 /* 2 * Shell Menu Desk Bar 3 * 4 * Copyright 2014 David Quintana 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 St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 #pragma once 21 22 typedef CWinTraits< 23 WS_POPUP | WS_DLGFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 24 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_PALETTEWINDOW 25 > CMenuWinTraits; 26 27 class CMenuDeskBar : 28 public CComCoClass<CMenuDeskBar, &CLSID_MenuDeskBar>, 29 public CComObjectRootEx<CComMultiThreadModelNoCS>, 30 public CWindowImpl<CMenuDeskBar, CWindow, CMenuWinTraits>, 31 public IOleCommandTarget, 32 public IServiceProvider, 33 public IInputObjectSite, 34 public IInputObject, 35 public IMenuPopup, 36 public IObjectWithSite, 37 public IBanneredBar, 38 public IInitializeObject 39 { 40 private: 41 CComPtr<IUnknown> m_Site; 42 CComPtr<IUnknown> m_Client; 43 CComPtr<IMenuPopup> m_SubMenuParent; 44 CComPtr<IMenuPopup> m_SubMenuChild; 45 46 HWND m_ClientWindow; 47 48 DWORD m_IconSize; 49 HBITMAP m_Banner; 50 51 BOOL m_Shown; 52 DWORD m_ShowFlags; 53 54 BOOL m_didAddRef; 55 56 virtual void OnFinalMessage(HWND hWnd); 57 public: 58 CMenuDeskBar(); 59 virtual ~CMenuDeskBar(); 60 61 DECLARE_REGISTRY_RESOURCEID(IDR_MENUDESKBAR) 62 DECLARE_NOT_AGGREGATABLE(CMenuDeskBar) 63 DECLARE_PROTECT_FINAL_CONSTRUCT() 64 65 DECLARE_WND_CLASS_EX(_T("BaseBar"), CS_SAVEBITS | CS_DROPSHADOW, COLOR_3DFACE) 66 67 BEGIN_MSG_MAP(CMenuDeskBar) 68 MESSAGE_HANDLER(WM_CREATE, _OnCreate) 69 MESSAGE_HANDLER(WM_SIZE, _OnSize) 70 MESSAGE_HANDLER(WM_NOTIFY, _OnNotify) 71 MESSAGE_HANDLER(WM_PAINT, _OnPaint) 72 MESSAGE_HANDLER(WM_ACTIVATE, _OnActivate) 73 MESSAGE_HANDLER(WM_ACTIVATEAPP, _OnAppActivate) 74 MESSAGE_HANDLER(WM_MOUSEACTIVATE, _OnMouseActivate) 75 MESSAGE_HANDLER(WM_WININICHANGE , _OnWinIniChange) 76 MESSAGE_HANDLER(WM_NCPAINT, _OnNcPaint) 77 MESSAGE_HANDLER(WM_CLOSE, _OnClose) 78 END_MSG_MAP() 79 80 BEGIN_COM_MAP(CMenuDeskBar) 81 COM_INTERFACE_ENTRY_IID(IID_IMenuPopup, IMenuPopup) 82 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget) 83 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider) 84 COM_INTERFACE_ENTRY_IID(IID_IInputObjectSite, IInputObjectSite) 85 COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject) 86 COM_INTERFACE_ENTRY_IID(IID_IDeskBar, IMenuPopup) 87 COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IMenuPopup) 88 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite) 89 COM_INTERFACE_ENTRY_IID(IID_IBanneredBar, IBanneredBar) 90 COM_INTERFACE_ENTRY_IID(IID_IInitializeObject, IInitializeObject) 91 END_COM_MAP() 92 93 // *** IMenuPopup methods *** 94 STDMETHOD(Popup)(POINTL *ppt, RECTL *prcExclude, MP_POPUPFLAGS dwFlags) override; 95 STDMETHOD(OnSelect)(DWORD dwSelectType) override; 96 STDMETHOD(SetSubMenu)(IMenuPopup *pmp, BOOL fSet) override; 97 98 // *** IOleWindow methods *** 99 STDMETHOD(GetWindow)(HWND *phwnd) override; 100 STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override; 101 102 // *** IObjectWithSite methods *** 103 STDMETHOD(SetSite)(IUnknown *pUnkSite) override; 104 STDMETHOD(GetSite)(REFIID riid, PVOID *ppvSite) override; 105 106 // *** IBanneredBar methods *** 107 STDMETHOD(SetIconSize)(DWORD iIcon) override; 108 STDMETHOD(GetIconSize)(DWORD* piIcon) override; 109 STDMETHOD(SetBitmap)(HBITMAP hBitmap) override; 110 STDMETHOD(GetBitmap)(HBITMAP* phBitmap) override; 111 112 // *** IInitializeObject methods *** 113 STDMETHOD(Initialize)(THIS) override; 114 115 // *** IOleCommandTarget methods *** 116 STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText) override; 117 STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override; 118 119 // *** IServiceProvider methods *** 120 STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObject) override; 121 122 // *** IInputObjectSite methods *** 123 STDMETHOD(OnFocusChangeIS)(LPUNKNOWN lpUnknown, BOOL bFocus) override; 124 125 // *** IInputObject methods *** 126 STDMETHOD(UIActivateIO)(BOOL bActivating, LPMSG lpMsg) override; 127 STDMETHOD(HasFocusIO)(THIS) override; 128 STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg) override; 129 130 // *** IDeskBar methods *** 131 STDMETHOD(SetClient)(IUnknown *punkClient) override; 132 STDMETHOD(GetClient)(IUnknown **ppunkClient) override; 133 STDMETHOD(OnPosRectChangeDB)(LPRECT prc) override; 134 135 private: 136 // message handlers 137 LRESULT _OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 138 LRESULT _OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 139 LRESULT _OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 140 LRESULT _OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 141 LRESULT _OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 142 LRESULT _OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 143 LRESULT _OnAppActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 144 LRESULT _OnWinIniChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 145 LRESULT _OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 146 LRESULT _OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 147 148 HRESULT _AdjustForTheme(BOOL bFlatStyle); 149 BOOL _IsSubMenuParent(HWND hwnd); 150 HRESULT _CloseBar(); 151 }; 152