Wednesday, January 19, 2011

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?

  • Radio buttons and check buttons are just buttons. Use a CButton control and use GetCheck/SetCheck.

    From mos
  • Going on what mos said, the following worked did the trick:

    CButton* pButton = (CButton*)GetDlgItem(IDC_RADIOBUTTON);
    pButton->SetCheck(true);
    
    Roel : Please vote his answer up, then.
  • Use CheckRadioButton to set select one button in a group and GetCheckedRadioButton to retrieve the ID of the selected button.

    From ChrisN

0 comments:

Post a Comment