Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


{
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
}


  1. Execute the program and click the Ingrdients button:

  2. Return to MSVC


19.2.4..Check Box Events...............................................................................


Like all other MFC buttons, the check box can natively send only the click and the
double-click messages. These messages respectively are BN_CLICKED and
BN_DOUBLECLICKED, which originate when the user clicks or double-clicks the
control. If you need to, you can use either the events of the parent window or hand code
the messages yourself.

Practical Learning: Using Check Boxes Messages



  1. If the user completely removes the check mark on the Sweetener control, this
    suggests that the customer does not want this item on the sandwich. Consequently,
    the radio buttons in the Options group should be disabled. When the user clicks a
    check box, whether the control was already checked or not, the BN_CLICKED
    message is sent. Therefore, in this case, the first thing you should do it to check the
    state of the check button and then implement a behavior accordingly.
    Display the Customer Menu dialog box. Right-click the Sweetener control

  2. If you are using MSVC 6, click Events
    If you are using MSVC 7, click Add Event Handler

  3. If you are using MSVC 6, double-click BN_CLICKED. Accept the suggested name.
    Click OK and click Add And Edit
    If you are using MSVC 7, make sure the Message Type is set to BN_CLICKED and
    the Class List is set to CfastFoodDlg. Then click Add And Edit

  4. Implement the event as follows:


void CFastFoodDlg::OnBnClickedChkSweetener()
{
Free download pdf