菜单加入背景图片?那就要看你实现些什么功能!---------------------------- 你看看下面这派生类的定义,好多哦!! class CMenuXP : public CMenu { DECLARE_DYNAMIC(CMenuXP)public: CMenuXP(); virtual ~CMenuXP(); //Menu style(Default: STYLE_OFFICE) typedef enum { STYLE_OFFICE, //Draw a float button around the icon STYLE_STARTMENU, //show selected bar below the icon STYLE_XP //use different color for the icon area } MENUSTYLE; //Below is the functions to build the menu BOOL AddSideBar(CMenuXPSideBar *pItem); BOOL AppendODMenu(UINT nFlags, CMenuXPItem *pItem, ACCEL *pAccel=0); BOOL AppendSeparator(void); BOOL AppendODPopup(UINT nFlags, CMenuXP *pPopup, CMenuXPItem *pItem); void Break(void); //change a column(the next item added will be in a new column) void BreakBar(void); //change a column with a break line(same as Break, except that a break line is drawn between two columns)protected: CFont m_fontMenu; COLORREF m_clrBackGround; //Background color COLORREF m_clrSelectedBar; //selected bar color COLORREF m_clrText; //Text color COLORREF m_clrSelectedText; //selected text color COLORREF m_clrDisabledText; //disabled text color COLORREF m_clrSideBarStart; //Start color of the gradient sidebar COLORREF m_clrSideBarEnd; //end color of the gradient sidebar COLORREF m_clrIconArea; //Background color of the button(icon) area BOOL m_bBreak; //if true, next item inserted into the menu will be added with the sytle MF_MENUBREAK BOOL m_bBreakBar; //if true, next item inserted into the menu will be added with the sytle MF_MENUBARBREAK HBITMAP m_hBitmap; //Background bitmap CDC m_memDC; //Memory dc holding the background bitmap MENUSTYLE m_Style; //menu style(currently support office or startmenu style)public: //User these functions to change the default attribute of the menu void SetBackColor(COLORREF clr) { m_clrBackGround = clr; } void SetSelectedBarColor(COLORREF clr) { m_clrSelectedBar = clr; } void SetTextColor(COLORREF clr) { m_clrText = clr; } void SetSelectedTextColor(COLORREF clr) { m_clrSelectedText = clr; } void SetDisabledTextColor(COLORREF clr) { m_clrDisabledText = clr; } void SetSideBarStartColor(COLORREF clr) { m_clrSideBarStart = clr; } void SetSideBarEndColor(COLORREF clr) { m_clrSideBarEnd = clr; } void SetIconAreaColor(COLORREF clr) { m_clrIconArea = clr; } void SetBackBitmap(HBITMAP hBmp);
可以去查查
你看看下面这派生类的定义,好多哦!!
class CMenuXP : public CMenu
{
DECLARE_DYNAMIC(CMenuXP)public:
CMenuXP();
virtual ~CMenuXP(); //Menu style(Default: STYLE_OFFICE)
typedef enum
{
STYLE_OFFICE, //Draw a float button around the icon
STYLE_STARTMENU, //show selected bar below the icon
STYLE_XP //use different color for the icon area
} MENUSTYLE; //Below is the functions to build the menu
BOOL AddSideBar(CMenuXPSideBar *pItem);
BOOL AppendODMenu(UINT nFlags, CMenuXPItem *pItem, ACCEL *pAccel=0);
BOOL AppendSeparator(void);
BOOL AppendODPopup(UINT nFlags, CMenuXP *pPopup, CMenuXPItem *pItem);
void Break(void); //change a column(the next item added will be in a new column)
void BreakBar(void); //change a column with a break line(same as Break, except that a break line is drawn between two columns)protected:
CFont m_fontMenu;
COLORREF m_clrBackGround; //Background color
COLORREF m_clrSelectedBar; //selected bar color
COLORREF m_clrText; //Text color
COLORREF m_clrSelectedText; //selected text color
COLORREF m_clrDisabledText; //disabled text color COLORREF m_clrSideBarStart; //Start color of the gradient sidebar
COLORREF m_clrSideBarEnd; //end color of the gradient sidebar
COLORREF m_clrIconArea; //Background color of the button(icon) area BOOL m_bBreak; //if true, next item inserted into the menu will be added with the sytle MF_MENUBREAK
BOOL m_bBreakBar; //if true, next item inserted into the menu will be added with the sytle MF_MENUBARBREAK HBITMAP m_hBitmap; //Background bitmap
CDC m_memDC; //Memory dc holding the background bitmap MENUSTYLE m_Style; //menu style(currently support office or startmenu style)public: //User these functions to change the default attribute of the menu
void SetBackColor(COLORREF clr) { m_clrBackGround = clr; }
void SetSelectedBarColor(COLORREF clr) { m_clrSelectedBar = clr; }
void SetTextColor(COLORREF clr) { m_clrText = clr; }
void SetSelectedTextColor(COLORREF clr) { m_clrSelectedText = clr; }
void SetDisabledTextColor(COLORREF clr) { m_clrDisabledText = clr; }
void SetSideBarStartColor(COLORREF clr) { m_clrSideBarStart = clr; }
void SetSideBarEndColor(COLORREF clr) { m_clrSideBarEnd = clr; }
void SetIconAreaColor(COLORREF clr) { m_clrIconArea = clr; }
void SetBackBitmap(HBITMAP hBmp);
void SetMenuStyle(MENUSTYLE style) { m_Style = style; } BOOL SetMenuFont(LOGFONT lgfont);
//Find the popupmenu from a menuitem id, you may not need it
CMenuXP *FindSubMenuFromID(DWORD dwID);public:
virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct );
static LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);protected:
virtual void DrawBackGround(CDC *pDC, CRect rect, BOOL bSelected, BOOL bDisabled);
virtual void DrawButton(CDC *pDC, CRect rect, BOOL bSelected, BOOL bDisabled, BOOL bChecked);
virtual void DrawIcon(CDC *pDC, CRect rect, HICON hIcon, BOOL bSelected, BOOL bDisabled, BOOL bChecked);
virtual void DrawSideBar(CDC *pDC, CRect rect, HICON hIcon, CString strText);
virtual void DrawText(CDC *pDC, CRect rect, CString strText, BOOL bSelected, BOOL bDisabled, BOOL bBold);
virtual void DrawCheckMark(CDC *pDC, CRect rect, BOOL bSelected);
virtual void DrawMenuText(CDC& dc, CRect rc, CString text, COLORREF color);
virtual void DrawIconArea(CDC *pDC, CRect rect, BOOL bSelected, BOOL bDisabled, BOOL bChecked); void Clear(void); //Clean all memory and handles //helpers
HBITMAP CreateGradientBMP(HDC hDC,COLORREF cl1,COLORREF cl2,int nWidth,int nHeight,int nDir,int nNumColors);
void DrawEmbossed(CDC *pDC, HICON hIcon, CRect rect, BOOL bColor = FALSE, BOOL bShadow = FALSE);
void FillRect(CDC *pDC, const CRect& rc, COLORREF color);
};
----------------------------
有了这个才能到你的
XXXXView::OnContextMenu(CWnd* pWnd, CPoint point)
函数里去使用。
对于你的就是要:
CBitmap bmp;
bmp.LoadBitmap(IDB_BACK);
pMenu->SetBackBitmap((HBITMAP)bmp.Detach());
那么那个派生类怎么也要实现:
SetBackBitmap()吧:)那个例子里面是这么实现的。
void CMenuXP::SetBackBitmap(HBITMAP hBmp)
{
if (hBmp == NULL && m_hBitmap)
{
::DeleteObject(m_hBitmap);
m_hBitmap = NULL;
m_memDC.DeleteDC();
return;
}
m_hBitmap = hBmp;
if (!m_memDC.m_hDC)
{
CWindowDC dc(NULL);
m_memDC.CreateCompatibleDC(&dc);
} ASSERT(m_memDC.m_hDC); ::SelectObject(m_memDC.m_hDC, m_hBitmap);
}
具体的你还是找个例子看吧。共同学习。:)
在DrawItem里把背景画上去
CMainFrame::OnCreate(...)
{
CYourMenu* pMenu = new CYourMenu;
pMenu ->CreateMen();
SetMenu(pMenu);
}
重载\CMenu可以改弹出菜单,但是对于主框架菜单是不行的吧