Visual C++ and MFC Fundamentals Chapter 20: List-Based Controls
CIngredientsDlg Dlg;// = new CIngredientsDlg;
// Before displaying the dialog box, synchronize its
// check boxes with the state of the Ingredients check box
// If the Ingredients check box is not checked at all
if( IngredientState == 0 )
{
// then uncheck all the check boxes of the Ingredients dialog
Dlg.m_bLettuce = FALSE;
Dlg.m_bOnion = FALSE;
Dlg.m_bTomato = FALSE;
Dlg.m_bPickles = FALSE;
} // If the Ingredients check box is checked
else if( IngredientState == 1 )
{
// then check all the check boxes of the Ingredients dialog
Dlg.m_bLettuce = TRUE;
Dlg.m_bOnion = TRUE;
Dlg.m_bTomato = TRUE;
Dlg.m_bPickles = TRUE;
} // Since the Ingredients check box appears indeterminate,
else if( IngredientState == 2 )
{
// select the lettuce and the tomato
Dlg.m_bLettuce = TRUE;
Dlg.m_bOnion = FALSE;
Dlg.m_bTomato = TRUE;
Dlg.m_bPickles = FALSE;
}
// Now is the time to display the dialog box
// Call the Ingregients Selection dialog box for the user
// If the user clicked OK when closing the dialog box,
if( Dlg.DoModal() == IDOK )
{
// if no check box is checked
if( (Dlg.m_bLettuce == FALSE) &&
(Dlg.m_bOnion == FALSE) &&
(Dlg.m_bTomato == FALSE) &&
(Dlg.m_bPickles == FALSE) )
m_Regulars.SetCheck(0); // then uncheck this one
// if all check boxes are checked
else if( (Dlg.m_bLettuce == TRUE) &&
(Dlg.m_bOnion == TRUE) &&
(Dlg.m_bTomato == TRUE) &&
(Dlg.m_bPickles == TRUE) )
m_Regulars.SetCheck(1); // then check this one
else // if at least one check box is checked and at one is unchecked
m_Regulars.SetCheck(2); // then set this one as indeterminate
}
// If the user clicked Cancel, don't do nothing
}
- Now we can calculate the price of the sandwich.
In the CFastFoodDlg class, declare a member function of type void and named
EvaluatePrice
private:
void EvaluatePrice(void);
};