- MFC Tutorial
- MFC - Home
- MFC - Overview
- MFC - Environment Setup
- MFC - VC++ Projects
- MFC - Getting Started
- MFC - Windows Fundamentals
- MFC - Dialog Boxes
- MFC - Windows Resources
- MFC - Property Sheets
- MFC - Windows Layout
- MFC - Controls Management
- MFC - Windows Controls
- MFC - Messages & Events
- MFC - Activex Controls
- MFC - File System
- MFC - Standard I/O
- MFC - Document View
- MFC - Strings
- MFC - Carray
- MFC - Linked Lists
- MFC - Database Classes
- MFC - Serialization
- MFC - Multithreading
- MFC - Internet Programming
- MFC - GDI
- MFC - Libraries
- MFC Useful Resources
- MFC - Quick Guide
- MFC - Useful Resources
- MFC - Discussion
MFC - Radio Buttons
A radio button is a control that appears as a dot surrounded by a round box. In reality, a radio button is accompanied by one or more other radio buttons that appear and behave as a group.
Here is the list of messages mapping for Radio Button control −
Message | Map entry | Description |
---|---|---|
BN_CLICKED | ON_BN_CLICKED( <id>, <memberFxn> ) | The framework calls this member function when is button clicked. |
BN_DISABLE | ON_BN_DISABLE( <id>, <memberFxn> ) | The framework calls this member function when button is disabled. |
BN_DOUBLECLICKED | ON_BN_DOUBLECLICKED( <id>, <memberFxn> ) | The framework calls this member function when button is double clicked. |
BN_PAINT | ON_BN_PAINT( <id>, <memberFxn> ) | The framework calls this member function when an application makes a request to repaint a button. |
Let us look into an example of Radio button by creating a new MFC dialog based application.
Step 1 − Drag a group box and three radio buttons and remove the Caption of Static Text control.
Step 2 − Add event handler for all the three radio buttons.
Step 3 − Add the Value variable for the Static Text control.
Step 4 − Here is the implementation of three event handlers.
void CMFCRadioButtonDlg::OnBnClickedRadio1() { // TODO: Add your control notification handler code here m_strTextControl = _T("Radio Button 1 Clicked"); UpdateData(FALSE); } void CMFCRadioButtonDlg::OnBnClickedRadio2() { // TODO: Add your control notification handler code here m_strTextControl = _T("Radio Button 2 Clicked"); UpdateData(FALSE); } void CMFCRadioButtonDlg::OnBnClickedRadio3() { // TODO: Add your control notification handler code here m_strTextControl = _T("Radio Button 3 Clicked"); UpdateData(FALSE); }
Step 5 − When the above code is compiled and executed, you will see the following output. When you select any radio button, the message is displayed on Static Text control.
To Continue Learning Please Login
Login with Google