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
- 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;
};
- 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;
}
}
- 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 - Select the Message Type as BN_CLICKED. Accept the name of the event as
OnBnClickedContainer - If you are using MSVC 6, click Add Handler, accept the name and click Edit
Existing
If using MSVC 7, click Edit Code - In the same way, add a BN_CLICKED event for the Cone and the Bowl radio
buttons - Implement the events as follows:
void CIceScreamOrderDlg::OnBnClickedContainer()