|
-
October 11th, 2008, 09:52 PM
#1
Crash while using CToolbar
In my application, I am using a CToolbar object to create two buttons.One button launches a calculator and the other one is an exit button to exit the application.
When clicking on the calculator button, the calc launches fine, however,when I click on the exit button, the application crashes.
Both of them load on the application init, so I believe there is no issue with the loading of the toolbar itself.....
Any Help regarding this....
-
October 12th, 2008, 07:48 AM
#2
Re: Crash while using CToolbar
Without knowing what the crash is about, it's virtually impossible to help you. What kind of error do you get and what does the debugger show you during the crash ?
-
October 12th, 2008, 11:56 AM
#3
Re: Crash while using CToolbar
What do your command handlers look like ?
-
October 12th, 2008, 01:23 PM
#4
Re: Crash while using CToolbar
-
October 13th, 2008, 06:58 AM
#5
Re: Crash while using CToolbar
The exception I get is an access violation ( 0x0000005) in MFC42.dll.
I believe it is because of some pointer becoming NULL and me trying to access it.
The PreTranslateMessage(...) does not get the message, but through the child windows, it reaches the OnCommand() function.
This is where I destroy the window and it seems like the message gets relayed back to the child windows and they crash....
Is there a way I can make sure that the message does not get relayed back...
since this is a window close event, can I write some code in the OnCommand() function itself that will make sure that my window gets completely destroyed and there is no message relayed back....
-
October 13th, 2008, 07:06 AM
#6
Re: Crash while using CToolbar
I think you should try to fix the problem with accessing a NULL pointer. Check the pointers for validity. And if the pointer is NULL and is not supposed to be NULL, then try to figure why it's NULL and fix that.
-
October 13th, 2008, 07:13 AM
#7
Re: Crash while using CToolbar
hmmm...
@cilu : you are right.
can you guide me with this help.
There is a window..and there is my toolbar on the window....
as soon as I click on the toolbar, how do I make sure that my window is notified of the event....
ON_BN_CLICKED does not seem to help,
It still goes into PreTranslateMessage with a mouse move event and then gets into the OnCommand(...) function in the parent window that a command has been executed.
So, when it returns from this function that the Command has been handled, the child windows have already been destroyed ( since the button is a exit button, I have written code to destroy everything), hence resulting in the crash...
The approach I was trying to look at it something like
As soon as I click on a button in the toolbar, handle the event here itself,
do not let the child windows know of it....
What should I do to achieve this??
-
October 13th, 2008, 10:51 AM
#8
Re: Crash while using CToolbar
Please post the code of the command handlers. Ideally, please post a compilable project that has just enough code to reproduce the error. Why are you destroying windows ? Did you create them yourself in the first place ?
-
October 22nd, 2008, 02:44 AM
#9
Re: Crash while using CToolbar
I have found the reason why it was happening....
It was because the command that the exit icon was being clicked was being relayed to the CDialog I have created by the components inside it.....but I was destroying these components before the message was relayed back.....
Instead of destroying instantly, I am now using CDialog::EndDialog(TRUE) to set a flag to destroy the components after the message was relayed back to the components which sent the command handler to my CDialog derived object.....
http://msdn.microsoft.com/en-us/libr...tw(VS.80).aspx
-
October 22nd, 2008, 02:45 AM
#10
Re: Crash while using CToolbar
Thanks a lot for the help guys......
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
|