Page 1 of 1
Dialog creation and destruction
Posted: Wed Jan 06, 2016 1:56 pm
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'
Re: Dialog creation and destruction
Posted: Wed Jan 06, 2016 4:00 pm
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.
Re: Dialog creation and destruction
Posted: Wed Jan 06, 2016 5:37 pm
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'
Re: Dialog creation and destruction
Posted: Wed Jan 06, 2016 9:56 pm
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.
Re: Dialog creation and destruction
Posted: Thu Jan 07, 2016 10:38 am
by Rob'
Thank you, doublemax!
Rob'