-
January 27th, 2004, 12:11 AM
#16
Originally posted by brraj
what do u say about Sam Hobbs comments ?
Sam is right. But as he says, you didn't specify where in a modeless dialog you mean. It depends on how the dialog is managed. Most often, with a modeless dialog, you keep a pointer to the CDialog object somewhere in your code. The dialog is instantiated, and then you call Create() and ShowWindow(). Now in OnOk / OnCancel, you have the choice of just closing the dialog (by calling ShowWindow with SW_HIDE) and keep the window object alive (for later use). In that case, the code "outside" which created the dialog would just need to delete the CDialog object later without having to call DestroyWindow() (as it is called in the dtor). However, a frequent scenario is that you want to destroy the window object in OnOk / OnCancel. Calling "delete this" would be a bad idea in this case, as it would leave the "outside" pointer to the CDialog object dangling. That's why you call DestroyWindow() in that case, leaving the CDialog object (without a valid HWND) alive. In order to redisplay the dialog, the "outside" code would have to call Create() once again, and reuse just the existing CDialog instance.
-
January 27th, 2004, 12:54 AM
#17
There are at least four possible scenarious for modeless dialogs, as follows:
- allocated by "new" and persists after the function that allocates it returns
- allocated by "new" but deleted prior to the function that allocates it returns
- allocated "on the stack" and therefore deleted automatically when the function that allocates it returns
- allocated as a class member variable
The corresponding actions we would typically need to do are:
- the dialog normally destroys itself (calls DestroyWindow in OnOk and OnCancel) and does the "delete this" in PostNcDestroy
- the "delete this" in PostNcDestroy is not needed if the object is deleted by the function that creates it
- no "delete this", since it would likely cause an error
- no "delete this", since it would likely cause an error
-
January 27th, 2004, 01:14 AM
#18
hi all,
I am calling the DestroyWindow in OnCancel.
SO i think for ctrls i will not call destroy window but only for modalless dialog i will call DestroyWindow as for ctrl it will automatically be called in destructors.
thanks samhobbs and gstercken for the comments
thanks
rajs
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
|