|
-
August 30th, 1999, 09:55 AM
#1
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
-
August 30th, 1999, 10:32 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|