Click here to Skip to main content
15,894,646 members
Articles / Desktop Programming / MFC

A Better Bitmap Button Class

Rate me:
Please Sign up or sign in to vote.
3.46/5 (14 votes)
14 Oct 2001 398.3K   9.2K   80  
An improvement on the CBitmapButton class.
#if !defined(AFX_TOGGLEBUTTON_H__711AF673_BCE0_11D3_9FE1_006067718D04__INCLUDED_)
#define AFX_TOGGLEBUTTON_H__711AF673_BCE0_11D3_9FE1_006067718D04__INCLUDED_

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

/////////////////////////////////////////////////////////////////////////////
// CToggleButton window

class CToggleButton : public CButton
{
// Construction
public:
	CToggleButton();

// Attributes
public:

// Operations
public:
   DWORD SetHPos(DWORD style); // Set the horizonatal alignment style
   DWORD SetVPos(DWORD style); // Set the vertical alignment style
   BOOL GetState() { return depressed; } // returns state, TRUE if depressed
   BOOL SetState(BOOL newstate)
	 { BOOL old = depressed; depressed = newstate;
           InvalidateRect(NULL); return old; } // sets new state, returns old state
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CToggleButton)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CToggleButton();

	// Generated message map functions
protected:
   BOOL depressed;
	//{{AFX_MSG(CToggleButton)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

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

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

#endif // !defined(AFX_TOGGLEBUTTON_H__711AF673_BCE0_11D3_9FE1_006067718D04__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
Retired
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

Comments and Discussions