Dialog creation and destruction

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Rob'
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Dec 08, 2008 10:10 pm

Dialog creation and destruction

Post by Rob' »

I have some general questions:

To show a dialog I use the following code:

Code: Select all

myDialog* dlg = new myDialog(this);
dlg->ShowModal();
dlg->Destroy();
or alternativly:

Code: Select all

myDialog dlg(this);
dlg.ShowModal();
My questions are:
When I have to pass the this-pointer as the parent window and what happens, if I pass a NULL-pointer?
When I have to call Destroy() and delete, resp. to remove the dialog?
What means "TopLevelWindow"? Are these windows without a parent?

Thanks in advance.
Rob'
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Dialog creation and destruction

Post by doublemax »

When I have to pass the this-pointer as the parent window and what happens, if I pass a NULL-pointer?
Passing NULL as parent is valid for toplevel windows.
When I have to call Destroy() and delete, resp. to remove the dialog?
Only when you create the dialog on the heap.
What means "TopLevelWindow"? Are these windows without a parent?
wxFrame and wxDialog are the only classes that derive from wxToplevelWindow. That should already clarify what it means. These are the only windows that can be created without a parent and can have caption bar, menubar etc. From a user's point of view they are the "outer" windows that the user can resize, move around, minimize, maximize etc through OS controls.
Use the source, Luke!
Rob'
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Dec 08, 2008 10:10 pm

Re: Dialog creation and destruction

Post by Rob' »

Thanks for your reply.

That means:
The dialogs I have created with new, I have to remove with "delete". In my 2nd example I should call Destroy() after ShowModal(). Is that correct?

And a last question:
What are the differences in passing a NULL pointer or not? Both variants work fine.

Rob'
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Dialog creation and destruction

Post by doublemax »

The dialogs I have created with new, I have to remove with "delete". In my 2nd example I should call Destroy() after ShowModal(). Is that correct?
Yes.
What are the differences in passing a NULL pointer or not? Both variants work fine.
The main difference would be that if you pass a parent pointer, the window will get automatically destroyed when its parent is destroyed.
Use the source, Luke!
Rob'
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Dec 08, 2008 10:10 pm

Re: Dialog creation and destruction

Post by Rob' »

Thank you, doublemax!

Rob'
Post Reply