CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Sep 2002
    14 39'19.65"N / 121 1'44.34"E
    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.

  2. #17
    Join Date
    May 1999
    Southern California
    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
    My web site is Simple Samples.
    C# Corner Editor

  3. #18
    Join Date
    Jun 2002
    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


Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)