Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

MFC extension library - A plugin to handle owner drawn menus

, 11 May 2004
Continuation of the Plugin Architecture series
// Some plug-in header
//
//////////////////////////////////////////////////////////////////////

#if !defined(MY_MAINFRAME_PLUG_IN)
#define MY_MAINFRAME_PLUG_IN

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning(disable : 4786)
#include <map>

// how the menu's are drawn, either original or XP style
typedef enum {BCMENU_DRAWMODE_ORIGINAL,BCMENU_DRAWMODE_XP} BC_MenuDrawMode;

// how seperators are handled when removing a menu (Tongzhe Cui)
typedef enum {BCMENU_NONE, BCMENU_HEAD, BCMENU_TAIL, BCMENU_BOTH} BC_Seperator;

class CODMenu : public CPlugInMap  
{
public:
	DECLARE_DYNCREATE(CODMenu)

	CODMenu();
	CODMenu(bool special);
	virtual ~CODMenu();

// Attributes
public:
// Operations
public:
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CODMenu)
	//}}AFX_VIRTUAL
	virtual CPlugInMap*		CreateMapObject() ;
	virtual bool			IsPlugInFor(CRuntimeClass *pClass);
	static void				EnumerateAndLoadToolbars();

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CODMenu)
	afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	//}}AFX_MSG
#ifdef _DEBUG
	afx_msg void OnMenuDebug();
	afx_msg void OnUpdateMenuDebug(CCmdUI *pCmdUI);
#endif

	DECLARE_MESSAGE_MAP()
private:
	static BOOL		GetBitmapFromImageList(CDC* pDC,CImageList *imglist,int nIndex,CBitmap &bmp);
	static void		DitherBlt2(CDC *drawdc, CBitmap &bmp, COLORREF bgcolor);
	static void		DitherBlt3(CDC *drawdc, CBitmap &bmp, COLORREF bgcolor);
	static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG lParam);
	static void		GetDisabledBitmap(CBitmap &bmp, COLORREF background);
	static COLORREF	LightenColor(COLORREF col,double factor);
	
	void			MeasureItem(LPMEASUREITEMSTRUCT lpMIS);
	void			DrawItem(LPDRAWITEMSTRUCT lpDIS);
	BOOL			IsLunaMenuStyle();
	BOOL			IsNewShell();
	BOOL			IsWinXPLuna();
	BOOL			IsWindowsClassicTheme();
	void			DrawItem_Win9xNT2000(LPDRAWITEMSTRUCT lpDIS);
	void			DrawItem_WinXP(LPDRAWITEMSTRUCT lpDIS);
	COLORREF		DarkenColor(COLORREF col,double factor);
	BOOL			Draw3DCheckmark(CDC *dc, const CRect& rc, BOOL bSelected, HBITMAP hbmCheck);
	BOOL			DrawXPCheckmark(CDC *dc, const CRect& rc, HBITMAP hbmCheck,COLORREF &colorout,BOOL selected);
	void			DrawRadioDot(CDC *pDC,int x,int y,COLORREF color);
	void			DrawCheckMark(CDC* pDC,int x,int y,COLORREF color,BOOL narrowflag=FALSE);

	static CFont	m_menuFont;
	static CFont	m_menuFontBold;
	static int		m_iconX;
	static int		m_iconY;
	static std::map<int, int>	m_commandToImage;
	// button images lists for normal/disabled states
	static CImageList	m_buttonImages;
	static CImageList	m_disabledImages;

	HMENU			m_menuBeingProcessed;
	bool			m_bSysMenu;				// true if prcoessing a system menu
	int				m_minSystemMenuWidth;	// min width of a system menu for correct drawing
#ifdef _DEBUG
	static int		m_pluggedInCount;
	friend class CDebugMenu;
#endif
};

#endif // !defined(MY_MAINFRAME_PLUG_IN)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Roger Allen
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.
 
I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)
 
I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

| Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 12 May 2004
Article Copyright 2004 by Roger Allen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid