[ACCEPTED]-Programmatically select an MFC radio button-mfc

Accepted answer
Score: 19

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

Score: 8

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

Score: 8

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

CButton* pButton = (CButton*)GetDlgItem(IDC_RADIOBUTTON);
pButton->SetCheck(true);
Score: 1
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
  ...
  DDX_Radio(pDX, IDC_RADIO1, m_Radio);
  ...
}

but it is the same thing Wizard generates

0

Score: 1

You can use this one-liner:

::SendMessage(GetDlgItem(IDC_RADIO1)->m_hWnd, BM_SETCHECK, BST_CHECKED, NULL);

0

More Related questions