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.
Create
Creates the Windows button control and attaches it to the CButton object.
DrawItem
Override to draw an owner-drawn CButton object.
GetBitmap
Retrieves the handle of the bitmap previously set with SetBitmap.
GetButtonStyle
Retrieves information about the button control style
GetCursor
Retrieves the handle of the cursor image previously set with SetCursor. 
GetIcon
Retrieves the handle of the icon previously set with SetIcon.
GetIdealSize
Retrieves the ideal size of the button contro.
GetImageList
Retrieves the image list of the button control.
GetNote
Retrieves the note component of the current command link control.
GetNoteLength
Retrieves the length of the note text for the current command link control.
GetSplitGlyph
Retrieves the glyph associated with the current split button control.
GetSplitImageList
Retrieves the image list for the current split button control.
GetSplitInfo
Retrieves information that defines the current split button control.
GetSplitSize
Retrieves the bounding rectangle of the drop-down component of the current split button control.
GetSplitStyle
Retrieves the split button styles that define the current split button control.
GetState
Retrieves the check state, highlight state, and focus state of a button control.
GetTextMargin
Retrieves the text margin of the button control.
SetBitmap
Specifies a bitmap to be displayed on the button.
SetButtonStyle
Changes the style of a button.
SetCheck
Sets the check state of a button control.
SetCursor
Specifies a cursor image to be displayed on the button.
SetDropDownState
Sets the drop-down state of the current split button control.
SetIcon
Specifies an icon to be displayed on the button.
SetImageList
Sets the image list of the button control.
SetNote
Sets the note on the current command link control.
SetSplitGlyph
Associates a specified glyph with the current split button control.
SetSplitImageList
Associates an image list with the current split button control.
SetSplitInfo
Specifies information that defines the current split button control.
SetSplitSize
Sets the bounding rectangle of the drop-down component of the current split button control.
SetSplitStyle
Sets the bounding rectangle of the drop-down component of the current split button control.
SetState
Sets the highlighting state of a button control.
SetTextMargin
Sets the text margin of the button control.
Here is the list of messages mapping for Radio Button control −
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.
 Print
 Add Notes
 Bookmark this page