Visual C++ and MFC Fundamentals Chapter 20: List-Based Controls
}
To find out what radio button of a group is selected, you can call the
CWnd::GetCheckedRadioButton(). Its syntax is:
int GetCheckedRadioButton( int nIDFirstButton, int nIDLastButton );
When calling this method, you must specify the identifier of the first radio button of the
group as nIDFirstButton and the identifier of the last radio button of the group as
nIDLastButton. The method returns the identifier of the radio button whose circle is
filled.
Alternatively, to find the selected radio button, call the CButton::GetCheck() method.
Its syntax is:
int GetCheck( ) const;
This method returns 0 if the radio button is not selected. Otherwise, it returns 1 if the
radio button is selected.
If you want to want to find whether a particular radio button is currently selected, you can
call the CWnd::IsDlgButtonChecked() method. Its syntax:
UINT IsDlgButtonChecked(int nIDButton) const;
When calling this method, pass the identifier of the radio button as the nIDButton
argument. This member function will check the state of the radio button. If the radio
button is selected, the method will return 1. If the radio button is not selected, the method
returns 0.
Practical Learning: Selecting Radio Buttons
- Add a Control variable for the IDC_FLAVORS radio button and name it m_Flavors
- In the same way, add a Control variable for the IDC_CONTAINER,
IDC_INGREDIENT, and IDC_SCOOPS named m_Container, m_Ingredient, and
m_Scoops respectively - Add a CString value variable for the IDC_PRICE edit control and name it m_Price