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?
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.

'CButton::GetCheck()' ( or 'CButton::SetCheck()' ( will do that for your. See also the article at ("Avoiding GetDlgItem") that sheds in some light about how MFC handles that.
DickStoneAuthor Commented:
I tried


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.
Well, That should be more like

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


Open in new window


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.

Be sure to also check out ("Avoiding GetDlgItem") - the title says why ;o)
Still having trouble?
DickStoneAuthor Commented:
Quick response. Also followed up to see if I was doing OK.
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

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.