Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals
// TODO: Add your control notification handler code here
// Get the state of the Sweetener check box
int CurState = IsDlgButtonChecked(IDC_CHK_SWEETENER);
// Get a handle to the radio buttons of the Options group
CWnd *rdoKetchup, *rdoMustard;
rdoKetchup = reinterpret_cast<CButton *>(GetDlgItem(IDC_KETCHUP));
rdoMustard = reinterpret_cast<CButton *>(GetDlgItem(IDC_MUSTARD));
// If the Sweetener check box is not checked
if( CurState == 0 )
{
// Disable the Options radio buttons
m_SweetOptions.EnableWindow(FALSE);
rdoKetchup->EnableWindow(FALSE);
rdoMustard->EnableWindow(FALSE);
}
else
{
// Otherwise, enable the Options radio buttons
m_SweetOptions.EnableWindow(TRUE);
rdoKetchup->EnableWindow(TRUE);
rdoMustard->EnableWindow(TRUE);
}
}
- Now, we will give complete or more control to the user with regards to the
ingredients. When the Regulars check box is not checked at all, no basic ingredient is
selected, when this control is checked, all ingredients will be added to the sandwich.
If at least one ingredient is selected and at least one ingredient is not selected, the
Regulars check box should appear dimmed.
To implement this, first access the OnInitDialog() event of the CIngredientsDlg
class and delete the initializations of its check boxes:
BOOL CIngredientsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// CheckDlgButton(IDC_CHK_LETTUCE, BST_CHECKED);
// CheckDlgButton(IDC_CHK_TOMATO, BST_CHECKED);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
- When the user clicks the Ingredients button, we will display the Ingredients Selection
dialog box and allow the user to select the ingredients. If the user clicks OK to
dismiss the dialog box, we will apply the above scenario.
Access the OnBnClickedBtnIngredients() event of the main dialog box and change
its code as follows:
void CFastFoodDlg::OnBnClickedBtnIngredients()
{
// TODO: Add your control notification handler code here
// Check the Ingredients check box state
int IngredientState = IsDlgButtonChecked(IDC_CHK_REGULARS);
// A variable for the Ingredients dialog box