Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / MFC

Custom Draw Buttons & A Smarter Groupbox

Rate me:
Please Sign up or sign in to vote.
4.64/5 (11 votes)
11 Jan 2000 207K   5.6K   78  
A class to make working with radio buttons easier, and another for custom drawing buttons
//---------------------------------------------------------------------------
//	THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. 
//	THE AUTHOR DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, 
//	INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
//	PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
//	ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, 
//	CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, 
//
//	By John Curtis, Dec 1999.   
//---------------------------------------------------------------------------

#ifndef _CCUSTOMICONBUTTON_
#define _CCUSTOMICONBUTTON_

#ifndef _CCUSTOMBUTTON_
#include "CCustomButton.h"
#endif

///////////////////////////////////////////////////////////////////////
//	Class CCustomIconButton
//
//	This class demonstrates the use of CCustomButton.
//	CCustomIconButton is derived from CCustomButton and draw a custom
//	button based on an indexed bitmap taken from a toolbar style strip bitmap.	
//	
///////////////////////////////////////////////////////////////////////

class CCustomIconButton :public CCustomButton
{
	DECLARE_DYNAMIC(CCustomIconButton)

public:
	CCustomIconButton(){}
	virtual ~CCustomIconButton(){}

	//Loads the image from a toolbar-style strip bitmap. 
	//nOffset is the 1 based offset of the icon.
	BOOL LoadIcon(UINT nBitMapID,int nOffset,CSize sz=CSize(16,15));
	BOOL LoadIcon(UINT nBitMapID,CSize sz=CSize(16,15)){return LoadIcon(nBitMapID,1,sz);}

protected:
	virtual	bool	CustomDraw()const{return true;}	//Return TRUE so Draw() is called
	virtual	void	OnDraw(CDC* pDC,const CCustomButtonState& state);//Custom drawing of IconButton
	virtual	bool	ModifyHitRegion(const CRect& Client,CHitRgn& hitRgn);//Override to define own hit testing
	virtual	bool	HoverEffects()const{return s_Hovering;}
	virtual	void	OnHover(bool bEnteringButton);	
	DECLARE_MESSAGE_MAP()

protected:
	CImageList	m_Image;	//Store the image in an image list for convenience
	CSize				m_Size;		//Cache the size of the bitmap.

	CRect				GetIconRect(CRect rClient)const;

public:
	static bool	s_Hovering;
};

#endif

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 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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions