CMenuEX - A Bitmap Menu Class






2.40/5 (8 votes)
Jan 5, 2001

152660

1605
Implementing an Ownerdrawn menu
Introduction
MS Visual Studio and MS Office products have menus with bitmaps next to commands which are associated with toolbar buttons. The aim of this class was to provide a quick and easy method of implementing these types of menus. The menu class can be used to replace the mainframe window menu as well being used as a context menu.
Implementation
Files
- ToolBarWrapper.h & ToolBarWrapper.cpp (Toolbar resource wrapper)
- MenuEx.h & MenuEx.cpp (principle
Menu
class)
Add the above files to your project.
Next add the view header file to your projects header file where the menu is to be used for instance Mainfrm.h.
#include "MenuEx.h"
CMenuEx
is the class to be included to implement the menu.
class CMainFrame : public CFrameWnd
{
... Some other code
CMenuEx m_menu;
};
To initialise the menu for a frame window, call CMenuEx::Initialize
in the OnCreate
procedure.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// MENUEX_ADD - Mainframe menu is initialized with parent window
if (!m_menu.Initialize(IDR_MAINFRAME,this))
return -1;
... Some other code
We now need to provide support for sizing and drawing the menu, that requires processing the WM_MEASUREITEM
and WM_DRAWITEM
messages. Use the class wizard to create the message handlers (Note: You change the message filter option in the class wizard to Window).
Menu items which use the Radio feature in MFC require this adding to your project where the SetRadio
option is used to update the command user interface.
// Example message handle for radio buttons
void CMainFrame::OnUpdateRadioItem3(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_nRadioGroup == 3);
m_menu.SetRadio(pCmdUI,m_nRadioGroup == 3); // Set radio button here
}
That's it! The next versions will support the intelligent menus and the new fangled MS Visual Studio 7.0beta menus.
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.