CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Delaware, USA
    Posts
    12

    Modeless dialog appears, then dies

    I have an originally modal dialog I am trying to display modeless like this:
    CCatViewDlg CatViewDlg;
    CatViewDlg.Create(IDD_CATVIEW);
    CatViewDlg.ShowWindow(SW_SHOW);

    The dialog box appears on the screen, processes OnInitDialog(), the controls are visible briefly, then the dialog shuts down. Has anybody else encountered this problem and found a solution?

    Kevin



  2. #2
    Join Date
    Jul 1999
    Location
    Waterloo, Ontario
    Posts
    32

    Re: Modeless dialog appears, then dies

    Your problem is most likely caused by your CCatViewDlg object going out of scope. When the end of the current code block is reached, CatViewDlg will be destroyed, which means that the CDialog destructor will be called. If you look at CDialog::~CDialog, you'll see that it calls DestroyWindow.

    To get your dialog to remain active, you'll have to allocate memory for it using new. Then you can either hold onto the pointer and delete it at the appropriate time, or (and this is the preferred choice) you can override a CDialog method like PostNcDestroy to delete the this pointer. (PostNcDestroy is called after the window has been destroyed, so it's a good place to destroy your object.)


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured