-
August 20th, 2012, 10:57 AM
#1
creating and accessing a checkbox
Windows XP Pro, Visual Studio 2008, C++, MFC
Goal: use some checkboxes
Details:
Created a Dialog
Created a class for the dialog: C_Control_Logging
Created a checkbox: ID = IDC_CBOX_ENABLE_ALL_LOGGING
Right clicked checkbox and added a variable: m_cbox_logging_enabled
In the constructor is the code:
[code] m_c_box_logging_enabled.SetCheck( BST_CHECKED )[/code}
The result when stepping over this line of code is a popup saying:
Debug Assertion Failed!
The line of code referenced is in afxwin2.inl. I read this as a safety
check point telling me I have a fundamental error in the checkbox code.
I am suspecting that I am not getting the variable associated with the checkbox,
but don't know how to do that.
when I open the properties of the checkbox I don't recognize anything that
indicates that this checkbox is checked or not checked.
How do I get access to this checkbox?
What should I do different?
(BTW: I have been searching, but everything I find is either not C++ or involves creating a checkbox from scratch. I have already created a couple using the Dialog utilities and now just need to find out how to access them.)
Edit: Just so it is said, I can open and close the new dialog box.
Edit again: After reading some more in my text book, I see that my new class does not have an OnInitDialog() function. I supose that means I created the class incorrectly, but I don't see the error of my ways. The book says I can over-ride it, but I have not been able to find that property box yet.
Thank you for your time.
Last edited by bkelly; August 20th, 2012 at 11:34 AM.
-
August 20th, 2012, 12:13 PM
#2
Re: creating and accessing a checkbox
The checkbox doesn't exist when the dialog's constructor is called. Override OnInitDialog and put your code after the call to CDialog::OnInitDialog.
-
August 20th, 2012, 12:23 PM
#3
Re: creating and accessing a checkbox
OK, I think I understand, but there is no OnInitDialog()(.
After creating what I thought was a class for the dialog box, I have searched the entire solution and the only OnInitDialog() is the one for the main dialog. There is none for the new dialog box.
Given a new dialog box with the ID: IDD_DLG_CONTROL_LOGGING
And within that dialog there is a check box with ID: IDC_CBOX_ENABLE_ALL_LOGGING
And a class for the dialog box named: C_Control_Logging
What do I need to do to gain access to the checkboxes.
My Horton book shows there is a properties sheet that has someting that looks like a method to create an override. But I am unable to find it.
Last edited by bkelly; August 20th, 2012 at 12:24 PM.
Reason: add a phrase
-
August 20th, 2012, 12:28 PM
#4
Re: creating and accessing a checkbox
As I said, you need to override it.
-
August 20th, 2012, 12:33 PM
#5
Re: creating and accessing a checkbox
Originally Posted by bkelly
After creating what I thought was a class for the dialog box, I have searched the entire solution and the only OnInitDialog() is the one for the main dialog. There is none for the new dialog box.
VS 2008, MFC: add OnInitDialog - how?
Victor Nijegorodov
-
August 20th, 2012, 12:49 PM
#6
Re: creating and accessing a checkbox
In the class I just declared the method OnInitDialog() and in there I wrote:
Code:
CButton *m_ctl_Check = (CButton*) GetDlgItem( IDC_CBOX_ENABLE_ALL_LOGGING );
int status = m_ctlCheck->GetCheck();
m_ctlCheck->SetCheck( BST_CHECKED )
And it does leave the checkbox checked or uncheck per the argument.
I found the line of code for GetDlgItem in another thread. Is that the right way here?
In the Horton book, he indicates I can select the dialog box, right click it, and the popup contains an option to override the OnInitDialog(). I cannot find that dialog. Any instructions on how to find it.
None the less, I do have a method of getting to the checkboxes now.
Thanks for your time.
-
August 20th, 2012, 01:57 PM
#7
Re: creating and accessing a checkbox
Originally Posted by bkelly
In the class I just declared the method OnInitDialog()
You should not "just declare", you must override the OnInitDialog() method! See the link I posted in my previous reply.
Victor Nijegorodov
-
August 20th, 2012, 02:26 PM
#8
Re: creating and accessing a checkbox
Hello,
In that link I find:
1.Open the file MyDialog.h.
2.Select the Properties window.
3.Place the cursor on the line that reads class CMyDialog : public CDialog. (The top of the Properties window should show "CMyDialog VCCodeClass" - this is important, because the Properties window is highly context sensitive, and you get different options depending on the location of the cursor in the editor.)
At step 2 I ask: What Properties Window? If I right click the class name itself, there is no Properties selection. If I go to the Visual Studio tool bar and select the button Properties I don't find anything that looks like: class CMyDialog : public CDialog.
Please provide a bit more detail for me.
Thank you.
-
August 20th, 2012, 02:41 PM
#9
Re: creating and accessing a checkbox
Class View/right click on the class name. The last item on the pop up menu is properties when I do it. Or you can go to the resource editor and right click in the dialog and get a menu with the properties selection too.
-
August 20th, 2012, 02:53 PM
#10
Re: creating and accessing a checkbox
I did not know to go there. Now I am a step further down the path and am documenting what I am doing so when I forget, I can figure it out again.
Thank you for taking the time to reply.
Last edited by bkelly; August 20th, 2012 at 03:12 PM.
Reason: typo
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|