Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals
Practical Learning: Implementing Check Boxes
- To show that at least one sweetener sauce is selected, in the OnInitDialog() event of
the main (Customer Menu) dialog box, call the CheckDlgButton() method. Pass it
the ID of the Sweetener control and the BST_CHECKED constant - To show that some ingredients are selected by default for a sandwich, call the
CheckDlgButton() method. Pass it the ID of the Regulars control and the
BST_INDETERMINATE constant:
BOOL CFastFoodDlg::OnInitDialog()
{
CDialog::OnInitDialog();
...
// TODO: Add extra initialization here
m_Bread.SetCheck(1);
m_Meat.SetCheck(1);
m_SweetOptions.SetCheck(1);
m_TotalPrice.SetWindowText("$2.35");
CheckDlgButton(IDC_CHK_SWEETENER, BST_CHECKED);
CheckDlgButton(IDC_CHK_REGULARS, BST_INDETERMINATE);
return TRUE; // return TRUE unless you set the focus to a control
}
- Test the application:
- Close the dialog and return to MSVC
- Add an OnInitDialog event for the Ingredients dialog box (If you are using MSVC 6,
display the ClassWizard, select the CIngredientsDlg class and, in the Messages list,
double-click WM_INITDIALOG. If you are using MSVC 7, in Class View, click
CIngredientsDlg and, in the Properties window, click the Overrides button ; then
click the arrow of the OnInitDialog combo box and select the only item in the combo
box
- Implement the event as follows:
BOOL CIngredientsDlg::OnInitDialog()