Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


IDC_INGREDIENTS m_Ingredients IDC_OPTIONS M_SweetOptions
IDC_TOTAL_PRICE m_TotalPrice


  1. To create a basic sandwich based on what we know so far, in the OnInitDialog()
    event of the main dialog class, type the following:


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");

return TRUE; // return TRUE unless you set the focus to a control
}


  1. Add a BN_CLICKED event for the Ingredients button and implement it as follows:


// FastFoodDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FastFood1.h"
#include "FastFoodDlg.h"
#include "IngredientsDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void CFastFoodDlg::OnBnClickedBtnIngredients()
{
// TODO: Add your control notification handler code here
CIngredientsDlg Dlg;

Dlg.DoModal();
}


  1. Test the application


19.2.3..Check Box Methods............................................................................


Like the radio button, a check box is based on the CButton class. Therefore, to
programmatically create a check box, declare CButton variable or pointer using its
constructor. Here is an example:

CButton *HotTempered = new CButton;

After declaring a variable or a pointer to CButton, you can call its Create() method to
initialize the control. The syntax is the same as for the radio button. To make the button a
Free download pdf