// ChkBox.cpp : implementation file // #include "stdafx.h" #include "cldprn32.h" #include "ChkBox.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAttribCheckBox CAttribCheckBox::CAttribCheckBox(UINT uAssociatedControlID) : m_uAssociatedControlID(uAssociatedControlID), m_bChecked(FALSE), m_bInitiallyChecked(m_bChecked), m_bEnabled(TRUE) { } CAttribCheckBox::~CAttribCheckBox() { } BEGIN_MESSAGE_MAP(CAttribCheckBox, CButton) //{{AFX_MSG_MAP(CAttribCheckBox) ON_CONTROL_REFLECT(BN_CLICKED, OnClicked) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CAttribCheckBox::Initialize() { m_bInitiallyChecked = m_bChecked; SetCheck(m_bChecked ? 1 : 0); m_bEnabled = IsWindowEnabled(); GetParent()->GetDlgItem(m_uAssociatedControlID)->EnableWindow(m_bChecked); } BOOL CAttribCheckBox::EnableWindow(BOOL bEnable) { m_bEnabled = bEnable; GetParent()->GetDlgItem(m_uAssociatedControlID)->EnableWindow(bEnable && m_bChecked); return CWnd::EnableWindow(bEnable); } ///////////////////////////////////////////////////////////////////////////// // CAttribCheckBox message handlers void CAttribCheckBox::OnClicked() { m_bChecked = (GetCheck() == 1); // Enable the associated control if the check box is checked; otherwise, disable it GetParent()->GetDlgItem(m_uAssociatedControlID)->EnableWindow(m_bChecked); }