Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


void CControlsDlg::OnBnClickedRdoDontknow()
{
// TODO: Add your control notification handler code here
UpdateChoice();
}

Practical Learning: Implementing Radio Buttons



  1. When the clerk clicks a Container radio button, we will change the right picture
    based on the selected container.
    In the header file of the Customer Order dialog box class, declare a member variable
    named ContSelected and of type int


private:
int Selected;
};


  1. Generate the WM_PAINT message of the dialog box and implement it as follows:


void CIceScreamOrderDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
CBitmap Bmp;

switch(Selected)
{
case 0:
Bmp.LoadBitmap(IDB_CUP);
m_Picture.SetBitmap(Bmp);
break;
case 1:
Bmp.LoadBitmap(IDB_CONE);
m_Picture.SetBitmap(Bmp);
break;
case 2:
Bmp.LoadBitmap(IDB_BOWL);
m_Picture.SetBitmap(Bmp);
break;
}
}


  1. On the dialog box, right-click the Cup radio button
    If you are using MSVC 6, click Events
    If you are using MSVC 7, click Add Event Handler

  2. Select the Message Type as BN_CLICKED. Accept the name of the event as
    OnBnClickedContainer

  3. If you are using MSVC 6, click Add Handler, accept the name and click Edit
    Existing
    If using MSVC 7, click Edit Code

  4. In the same way, add a BN_CLICKED event for the Cone and the Bowl radio
    buttons

  5. Implement the events as follows:
    void CIceScreamOrderDlg::OnBnClickedContainer()

Free download pdf