How do I get/set information from a checkbox control in MFC

If I have a text control, I can get/set information as:

CString strVal;
GetDlgItem(nID)->      GetWindowText(strVal);
GetDlgItem(nID)->      GetWindowText(strVal);

What is the equivalent to get/set information from a checkbox control?
DickStoneAsked:
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.

jkrCommented:
'CButton::GetCheck()' (http://msdn.microsoft.com/en-US/library/8tba1y6f%28v=vs.110%29.aspx) or 'CButton::SetCheck()' (http://msdn.microsoft.com/en-us/library/31deb72x(v=vs.110).aspx) will do that for your. See also the article at http://www.codeproject.com/Articles/537/Avoiding-GetDlgItem ("Avoiding GetDlgItem") that sheds in some light about how MFC handles that.
0
DickStoneAuthor Commented:
I tried

GetDlgItem(nID)->CButton::SetCheck(BST_CHECKED);

This resulted in:
c:\wfree\runpage.cpp(1264): error C2039: 'CButton' : is not a member of 'CWnd'
2>          c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxwin.h(2286) : see declaration of 'CWnd'
2>c:\wfree\runpage.cpp(1264): error C2662: 'CButton::SetCheck' : cannot convert 'this' pointer from 'CWnd' to 'CButton &'
2>          Reason: cannot convert from 'CWnd' to 'CButton'
2>          Conversion requires a second user-defined-conversion operator or constructor    


P.S. I normally use variables, but there are 45 controls and it's easier to set up a loop on the controls.
0
jkrCommented:
Well, That should be more like

CButton* pCheck = (CButton*)GetDlgItem(nID);

pCheck->SetCheck(BST_CHECKED);

Open in new window

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DickStoneAuthor Commented:
That looks like it got it. I'll close this tomorrow if I don't get any additional comments.

Thanks
0
jkrCommented:
Be sure to also check out http://www.codeproject.com/Articles/537/Avoiding-GetDlgItem ("Avoiding GetDlgItem") - the title says why ;o)
0
jkrCommented:
Still having trouble?
0
DickStoneAuthor Commented:
Quick response. Also followed up to see if I was doing OK.
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
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.