to check the correct state of checkbox control

Hello Sir,

i want to check the value of check box control whether it is checked or not and on the basis of this want to take some actions.

i have taken a check box control and using MFC ClassWizard, i have mapped the control id value to a variable (bool).
but on the check/uncheck event of checkbox control, when i check the value of variable, it is always in false state.

How can i check the correct state of checkbox control(checked or unchecked)

Thanks and Regards

Munish Gupta



Answer this question

to check the correct state of checkbox control

  • Mervyn-w

    Please use the newsgroups for MFC questions: http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.vc.mfc&lang=en&cr=US

    This forum is for C++ language issues only.

    Also, please use descriptive subject lines.

    Thanks,

    Brian


  • irvendeep

    First you should map to a BOOL not a bool. (read this FAQ for the difference)

    Second, how do you check for the state Can you post the code

    The simplest way is like this:

    bool checked = (((CButton*)GetDlgItem(IDC_CHECKBOX))->GetCheck() == BST_CHECKED);



  • Sean D Wright

    you can use GetCheck() and SetCheck() method to Get and Set Check state of a Control.and if you want you also can assure that Control is on your App with the help of IsWindowVisible() method

    Thanx


  • to check the correct state of checkbox control