Link to home
Start Free TrialLog in
Avatar of jobrems
jobremsFlag for Afghanistan

asked on

How can I select a radio button programmatically in MFC?

Can I use SendDlgItemMessage()?

I see there is a CButton::SetCheck() method - but I don't see how to reference the button object created by the Resource editor. How can I ue SetCheck?
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In addition: This can anly be called within a member function of the dialog and only after the CDialog::OnInitialUpdate function is called ...

BTW, there's another option too: You can generate a CButton member with 'ClassWizard->Variables->Add variable' for that resource ID of type button ...
... or for a group of radio buttons you just create (the same way as above with 'AddVariable') an UINT member variable. You then can set this to be 0 for the first radio button, 1 for the second a.s.o. and call 'UpdateData(FALSE)' to set it - call 'UpdateData(TRUE)' later to recieve in that UINT variable which button was checked by the user.

ZOPPO
Avatar of jobrems

ASKER

Quick and easy solution - thanks!
Add to ZOPPO's comment.
The member variable must be associated to the first radio button in the group.