Click here to Skip to main content
15,896,505 members
Articles / Desktop Programming / MFC

A ToolBarCtrl Based Menubar Control

Rate me:
Please Sign up or sign in to vote.
4.85/5 (19 votes)
3 Dec 20011 min read 212.8K   4.3K   67  
A ToolBarCtrl based menubar control using CMenuXP
#if !defined(AFX_ToolBarXP_H__F739196A_2383_11D5_99BD_5254AB339987__INCLUDED_)
#define AFX_ToolBarXP_H__F739196A_2383_11D5_99BD_5254AB339987__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ToolBarXP.h : header file
//

struct TOOLBAR_DATA
{
	WORD wVersion;
	WORD wWidth;
	WORD wHeight;
	WORD wItemCount;

	WORD* items()
		{ return (WORD*)(this+1); }
};

/////////////////////////////////////////////////////////////////////////////
// CToolBarXP window

class  CToolBarXP : public CToolBarCtrl
{
// Construction
public:
	CToolBarXP();

// Attributes
private:
	COLORREF	m_clrBack;	
	COLORREF	m_clrHot;
	COLORREF	m_clrSelected;
	COLORREF	m_clrChecked;
	COLORREF	m_clrLine;

	BOOL		m_bDrawLine;	//Draw a line rect around the button when hot or selected

protected:
	void		PreDrawItem(CDC *pDC, const RECT &rect, UINT uState);

// Operations
public:
	void		SetBackColor(COLORREF clr) { m_clrBack = clr; }
	void		SetHotColor(COLORREF clr) { m_clrHot = clr; }
	void		SetSelectedColor(COLORREF clr) { m_clrSelected = clr; }
	void		SetCheckedColor(COLORREF clr) { m_clrChecked = clr; }
	void		SetLineColor(COLORREF clr) {m_clrLine = clr; }

	void		EnableDrawLine(BOOL b) { m_bDrawLine = b; };

	//Load a toolbar resource
	BOOL	LoadToolBar(UINT nID);


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CToolBarXP)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CToolBarXP();

	// Generated message map functions
protected:
	//{{AFX_MSG(CToolBarXP)
	//}}AFX_MSG
	afx_msg void OnCustomDraw( NMHDR * pNotifyStruct, LRESULT* result );
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ToolBarXP_H__F739196A_2383_11D5_99BD_5254AB339987__INCLUDED_)

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.


Written By
China China
I'm a chinese programer living in Shanghai, currently working for a software company whose main business is to deliver computer based testing. Software simulation for computer based testing and certifications is my main responsibility in this company. Execpt for software development, I like out-door activities and photography. I am willing to make friends in China and all over the world, so contact me if you have anything in common with meSmile | :)

Comments and Discussions