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.
Rob'
Knows some wx things
Knows some wx things
Posts: 46
Joined: Mon Dec 08, 2008 10:10 pm

Dialog creation and destruction

Postby Rob' » Wed Jan 06, 2016 1:56 pm

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: 12822
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Dialog creation and destruction

Postby doublemax » Wed Jan 06, 2016 4:00 pm

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'
Knows some wx things
Knows some wx things
Posts: 46
Joined: Mon Dec 08, 2008 10:10 pm

Re: Dialog creation and destruction

Postby Rob' » Wed Jan 06, 2016 5:37 pm

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: 12822
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Dialog creation and destruction

Postby doublemax » Wed Jan 06, 2016 9:56 pm

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'
Knows some wx things
Knows some wx things
Posts: 46
Joined: Mon Dec 08, 2008 10:10 pm

Re: Dialog creation and destruction

Postby Rob' » Thu Jan 07, 2016 10:38 am

Thank you, doublemax!

Rob'


Return to “Component Writing”

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests