Link to home
Start Free TrialLog in
Avatar of DickStone
DickStone

asked on

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?
Avatar of jkr
jkr
Flag of Germany image

'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.
Avatar of DickStone
DickStone

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
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
That looks like it got it. I'll close this tomorrow if I don't get any additional comments.

Thanks
Be sure to also check out http://www.codeproject.com/Articles/537/Avoiding-GetDlgItem ("Avoiding GetDlgItem") - the title says why ;o)
Still having trouble?
Quick response. Also followed up to see if I was doing OK.