Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / MFC

A Button Group Control

Rate me:
Please Sign up or sign in to vote.
4.69/5 (9 votes)
12 May 20013 min read 92.8K   2.1K   42  
An article showing a button group control used to create toolbar-type groups as seen in the Visual Studio options dialogs.
/////////////////////////////////////////////////////////////////////////////
//
// BUTTON GROUP CONTROL
// 
// (c) Andrew Peace 2001
//
// You may use and distribute this control in either source or compiled form
// by any means.  You may not, however, remove this notice from the header of
// this file, nor sell this control for profit with express permission from
// the author. 
//
// No responsibility will be taken for any damage caused by this control, 
// though it has been thoroughly tested.  If you find any bugs please let me
// know so that they can be fixed and incorporated into this source file.
//


#if !defined(AFX_BUTTONGROUPCTL_H__450BBB6B_1B32_4F84_A17C_0EED754EE8EC__INCLUDED_)
#define AFX_BUTTONGROUPCTL_H__450BBB6B_1B32_4F84_A17C_0EED754EE8EC__INCLUDED_

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

#include <afxtempl.h>
#include "BtnST.h"

// ButtonGroupCtl.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CButtonGroupCtl window

class CButtonGroupCtl : public CStatic
{
// Construction
public:
	CButtonGroupCtl();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CButtonGroupCtl)
	public:
	virtual BOOL DestroyWindow();
	protected:
	virtual void PreSubclassWindow();
	virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
public:
	void EnableButton(int nID, bool bEnabled = true);
	void SetImageList(CImageList * pImageList);
	void AddButton(int nID, int nImage, LPCTSTR pszToolTip);
	virtual ~CButtonGroupCtl();

	// Generated message map functions
protected:
	//{{AFX_MSG(CButtonGroupCtl)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG
	struct FLATBUTTON
	{
		~FLATBUTTON()
		{
			if (::IsWindow(btn.m_hWnd))
				btn.DestroyWindow();
		}
		int ID;
		int ImageNumber;
		CString Tooltip;

		CButtonST btn;
	};

	CList<FLATBUTTON *, FLATBUTTON *> m_Buttons;
	CImageList *m_pImageList;

	DECLARE_MESSAGE_MAP()
};

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

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

#endif // !defined(AFX_BUTTONGROUPCTL_H__450BBB6B_1B32_4F84_A17C_0EED754EE8EC__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.

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 Kingdom United Kingdom
Andrew is currently a student at the University of Cambridge, working towards a degree in Computer Science. The word 'working' is used here in a vague sense, with the hope that the reader will realise that the same sentence contained the word 'student'.

Aside from computing he has a strong interest in music, and enjoys the outdoors, particularly when the weather permits going out in them... To Andrew, cycling is fun, sailing is more fun, and the odd camping trip and walk is certainly what the doctor ordered.

In terms of programming experience, he first started writing programs for the Commodore Amiga using BASIC, after which he learned the joys of C and has never looked back. Since, he has added C++ and C# to his repotoire, along with a bunch of other crazy languages like ML that they like to teach in college.

Comments and Discussions