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?
jobremsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi jobrems,

the resource editor creates a resource ID for the button which you can use:

(I assume it's in a dialog)

...
CButton* pButton = (CButton*)GetDlgItem( IDC_RADIO1 ); // that's the ID the resource editor creates - you can change it for better readability
pButton->SetCheck( TRUE );
...

Hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZoppoCommented:
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 ...
0
ZoppoCommented:
... 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
0
jobremsAuthor Commented:
Quick and easy solution - thanks!
0
alb66Commented:
Add to ZOPPO's comment.
The member variable must be associated to the first radio button in the group.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.