Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / MFC

GroupControl

Rate me:
Please Sign up or sign in to vote.
4.72/5 (30 votes)
21 Feb 2005CPOL5 min read 239.7K   7.8K   107  
CButton-derived control to help with using groups.
////////////////////////////////////////////////////////////////////////////
// File:	GroupControl.h
// Version:	1.1
// Created:	17-Feb-2005
//
// Author:	Paul S. Vickery
// E-mail:	paul@vickeryhome.freeserve.co.uk
//
// CButton-derived class to make using groups easier. CGroupControl will 
// automatically show/hide or enable/disable controls within the group when 
// the group is shown/hidden or enabled/disabled. Also, if the group box is 
// moved then its controls are moved with it.
//
// You are free to use or modify this code, with no restrictions, other than
// you continue to acknowledge me as the original author in this source code,
// or any code derived from it.
//
// If you use this code, or use it as a base for your own code, it would be 
// nice to hear from you simply so I know it's not been a waste of time!
//
// Copyright (c) 2002-2005 Paul S. Vickery
//
////////////////////////////////////////////////////////////////////////////
// Version History:
//
// Version 1.1 - 17-Feb-2005
// =========================
// Added method "IgnoreControls" to allow the group box to be moved/sized etc
// without the controls within the group doing the same, i.e. causes the group 
// control to act as a normal group control. This is useful if other child 
// controls move all their siblings as with Peter Mares' CKCSideBannerWnd 
// banner control (http://www.codeproject.com/miscctrl/kcsidebannerwnd.asp).
// 
// Version 1 - 24-Jul-2002
// =======================
// Initial version
// 
////////////////////////////////////////////////////////////////////////////
// PLEASE LEAVE THIS HEADER INTACT
////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_GROUPCONTROL_H__6AEE0F71_9D52_11D6_860D_0000B48746CF__INCLUDED_)
#define AFX_GROUPCONTROL_H__6AEE0F71_9D52_11D6_860D_0000B48746CF__INCLUDED_

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

typedef BOOL (*GROUPCONTROLACTIONFUNC)(CWnd*, LPARAM);

/////////////////////////////////////////////////////////////////////////////
// CGroupControl window

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

// Attributes
public:

// Operations
public:
	BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CGroupControl)
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	BOOL IsInGroup(CWnd* pCtrl, BOOL& bOverlapped) const;
	void SetUseTabOrder(BOOL bUseTabOrder = TRUE) { m_bUseTabOrder = bUseTabOrder; }
	void SetAllowOverlap(BOOL bAllowOverlap = TRUE) { m_bAllowOverlap = bAllowOverlap; }
	BOOL GetUseTabOrder() const { return m_bUseTabOrder; }
	BOOL GetAllowOverlap() const { return m_bAllowOverlap; }
	BOOL DoGroupControlAction(GROUPCONTROLACTIONFUNC pfnGCAF, LPARAM lParam = 0) const;
	BOOL ControlsIgnored() const { return m_bIgnoreControls; }
	void IgnoreControls(BOOL bIgnore = TRUE) { m_bIgnoreControls = bIgnore; }
	virtual ~CGroupControl();

	// Generated message map functions
protected:
	BOOL m_bAllowOverlap;
	BOOL m_bUseTabOrder;

	BOOL m_bIgnoreControls;

	//{{AFX_MSG(CGroupControl)
	afx_msg void OnEnable(BOOL bEnable);
	afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

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

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

#endif // !defined(AFX_GROUPCONTROL_H__6AEE0F71_9D52_11D6_860D_0000B48746CF__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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
Originally from an electronics background, I moved into software in 1996, partly as a result of being made redundant, and partly because I was very much enjoying the small amount of coding (in-at-the-deep-end-C) that I had been doing!

I swiftly moved from C to C++, and learned MFC, and then went on to real-time C on Unix. After this I moved to the company for which I currently work, which specialises in Configuration Management software, and currently program mainly in C/C++, for Windows. I have been gradually moving their legacy C code over to use C++ (with STL, MFC, ATL, and WTL). I have pulled in other technologies (Java, C#, VB, COM, SOAP) where appropriate, especially when integrating with third-party products.

In addition to that, I have overseen the technical side of the company website (ASP, VBScript, JavaScript, HTML, CSS), and have also worked closely with colleagues working on other products (Web-based, C#, ASP.NET, SQL, etc).

For developing, I mainly use Visual Studio 2010, along with an in-house-designed editor based on Andrei Stcherbatchenko's syntax parsing classes, and various (mostly freeware) tools. For website design, I use Dreaweaver CS3.

When not developing software, I enjoy listening to and playing music, playing electric and acoustic guitars and mandolin.

Comments and Discussions