Programmatically select an MFC radio button


When I'm initializing a dialog, I'd like to select one of the radio buttons on the form. I don't see a way to associate a Control variable using the Class Wizard, like you would typically do with CButtons, CComboBoxes, etc…

Further, it doesn't like a CRadioButton class even exists.

How can I select one of the several radio buttons?

Best Solution

Use CWnd::CheckRadioButton to set select one button in a group and CWnd::GetCheckedRadioButton to retrieve the ID of the selected button. Be sure to call these methods on your dialog object, and not any of the radio button objects.