Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals


void CIceScreamOrderDlg::ProcessOrder(void)
{
double PriceFlavor, PriceContainer, PriceIngredient;
double TotalPrice;

int ContainerSelected = GetCheckedRadioButton(IDC_CONTAINER, IDC_RDO_BOWL);

if( ContainerSelected == IDC_CONTAINER )
PriceContainer = 0.35;
else if( ContainerSelected == IDC_RDO_CONE )
PriceContainer = 0.55;
else if( ContainerSelected == IDC_RDO_BOWL )
PriceContainer = 0.75;

int IngredientSelected = GetCheckedRadioButton(IDC_INGREDIENT, IDC_RDO_MIXEDNUTS);

if( IngredientSelected == IDC_INGREDIENT )
PriceIngredient = 0.00;
else if( IngredientSelected == IDC_RDO_MM )
PriceIngredient = 0.55;
else if( IngredientSelected == IDC_RDO_MIXEDNUTS )
PriceIngredient = 0.75;

int NumberOfScoops = GetCheckedRadioButton(IDC_SCOOPS, IDC_SCOOPS_THREE);
if( NumberOfScoops == IDC_SCOOPS )
PriceFlavor = 2.25;
else if( NumberOfScoops == IDC_SCOOPS_TWO )
PriceFlavor = 3.50;
else if( NumberOfScoops == IDC_SCOOPS_THREE )
PriceFlavor = 4.25;

TotalPrice = PriceContainer + PriceFlavor + PriceIngredient;

m_Price.Format("$%.2f", TotalPrice);
UpdateData(FALSE);
}


  1. To make sure the new member function is called whenever the user clicks a radio
    button, double-click each radio button on the dialog and accept the suggested name
    for the eventWhen a customer is passing an order and request his or her ice scream
    on a cone or a cup, because of the size of the cone or the cup, it cannot contain three
    scoops. Therefore, if the clerk selects the Cone or the Cup radio buttons upon the
    customer’s request, we can disable the Three radio button. While doing this, we must
    check whether the user had previously selected the Three radio button. If that button
    was selected, we should deselect it and select the One radio, giving the clerk the time
    to select the One or Two radio button.
    To implement this behavior, change the above events as follows:


void CIceScreamOrderDlg::OnBnClickedContainer()
{
// TODO: Add your control notification handler code here
// The first radio button was selected
Selected = 0;

// Get the rectangle that holds the picture
CRect PictArea;
m_Picture.GetWindowRect(&PictArea);
// Repaint the picture
Free download pdf