MFC check box question
Hello, I am somewhat new to windows programming and was wondering if someone could answer a question I have about some strange behavior. I have a row of check boxes that I am using to check individually, and also one check box called all that will check or uncheck all of the other boxes, according to if it is checked or unchecked itself. Here's what I am doing for normal check boxes.
What this does (or is supposed to do) is if the check is already set, unset it and set the member variable to false, otherwise it must be unchecked so we check it and set to true.
That code is in the single checkboxes, like check1, check2, check3, etc. However, it does not seem to work. When the box is unchecked, it goes to if and if it's checked it goes to the else. Now comes the strange part. In the check all check box I have code that looks like this.
CButton *btnPtr = (CButton *) GetDlgItem(IDC_CHECK_1);
m_check1 = false;
m_check1 = true;
When that code executes all the check boxes actually check and behave how I want them to. However when trying to check them individually they seem to function in the opposite manner. Does anyone know what could be the problem? Thank you.
m_check1_all = true;
When it goes into the button handler code, the GetCheck is returning the new state of the checkbox. Basically you are stopping it from doing what it wants to do. In your if statement block comment out your code and put a message box that displays "Checking", and in the else statement block do the same with a message box for "Unchecking". Then test.
However, you'll have to change your checkall function. Basically just set the check variables and call setcheck with appopriate values based on the checkall buttons state.
I also would make member variables for all the check boxes. It will make your code a little easier in your checkall function. You won't have to GetDlgItem four times.
Thank you so much Dave. I had not thought about the nature of the OnBnClicked function; returning the new state that had just resulted from clicking the button that is. This was in fact the problem. Thanks again for the quick response, it is very much appreciated.