CheckFrame Control



Sometimes it can be handy to exclude a set of options based on the users choice. For instance if the user do not want to save a log file, then it should be signalled, to the user, which options are relevant.

fig.1 The checkframe control are disabled, and so is its the contained controls.

fig. 2 The check frame is enabled and the controls can be used.


The header file: CheckFrm.h

BOOL IsRectContainedInRect(CRect &rcChild, CRect &rcMother);

class CCheckFrame : public CObject
	virtual void Enable(BOOL bEnable);
	void Set(CWnd *pParentWnd,UINT nFrmCtl);
	CWnd* m_pFrame; 
	CWnd* m_pDialog;
	CRect m_rFrm;
	CDWordArray m_adwWndHandles;

The impementation file: CheckFrm.cpp
The code are futher commented in the source files.

#include "stdafx.h"
#include "Checkfrm.h"

// EnumChildWnds Callback
BOOL CALLBACK EnumChildWnds(HWND hwnd, CCheckFrame *pObj)
	CRect R;
	GetWindowRect(hwnd, &R);
	if (hwnd != pObj->m_pFrame->m_hWnd)
		if (IsRectContainedInRect(R, pObj->m_rFrm))
	return TRUE;

// Function name	: Set
void CCheckFrame::Set(CWnd *pParentWnd, UINT nFrmCtl)
	m_pDialog = pParentWnd;
	// Calculate the size of the rect that should contain the controls
	m_pFrame = m_pDialog->GetDlgItem(nFrmCtl);
	if (!m_pFrame)
		AfxMessageBox("Unable to find frame control");
	// Make sure the array is empty
	// The (control) windows contained within the boundaries of the frame control
	// are enumerated and their associated window-handles collected in an array.
	EnumChildWindows(m_pDialog->m_hWnd, (WNDENUMPROC)EnumChildWnds, (LONG)(CCheckFrame *)this);

// Function name	: CCheckFrame::Enable
void CCheckFrame::Enable(BOOL bEnable)
	for (int i=0 ; i<m_adwWndHandles.GetSize() ; i++)
		EnableWindow((HWND)m_adwWndHandles[i], bEnable);

// Function name	: IsRectContainedInRect
BOOL IsRectContainedInRect(CRect &rcChild, CRect &rcMother)
	if (rcMother.PtInRect(CPoint(rcChild.left, &&
	rcMother.PtInRect(CPoint(rcChild.left, rcChild.bottom)) &&
	rcMother.PtInRect(CPoint(rcChild.right, &&
	rcMother.PtInRect(CPoint(rcChild.right, rcChild.bottom)))
		return TRUE;
	return FALSE;

Known problems:
If the checkbox control it self is disabled when the progrma exits, try to move it some pixels away from the border of the frame control.

Download the sample project (31 kb)

Posted : March 12, 98


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date