Creating a Modeless Dialog Box with MFC LibrariesLast reviewed: October 10, 1997Article ID: Q103788 |
1.00 1.50 1.51 1.52 | 1.00 2.00 2.10 4.00
WINDOWS | WINDOWS NTkbprg The information in this article applies to:
This article demonstrates how to create a modeless dialog box using a dialog-box template resource using MFC. To build a CModeless dialog box, the following steps should be followed:
CModeless * pdlg; NOTE: It is important to allocate the object on the heap rather than the stack if you want to prevent the modeless dialog box from being destroyed when the function is exited.
void CModeless::OnCancel() { DestroyWindow(); } virtual void CModeless::PostNcDestroy() {delete this;} PostNcDestroy() is a virtual member function of the CWnd class that is called by the OnNcDestroy() function. A modeless dialog class will typically override the OnOK() and OnCancel() member functions to call DestroyWindow() and should not call the base class CDialog::OnOK() and CDialog::OnCancel() functions. The CDialog::OnOK() and CDialog::OnCancel() functions call EndDialog(). EndDialog() should be called only when using modal dialog boxes. If you are using Dialog Data Exchange (DDX) and Dialog Data Validation (DDV), you're OnOK() handler for your dialog class might resemble the following:
void CModeless::OnOK() { if (!UpdateData(TRUE)) { TRACE0("UpdateData failed during dialog termination\n"); // The UpdateData routine will set focus to correct item return; } DestroyWindow(); } |
Additional reference words: kbinf 1.00 1.50 2.00 2.10 2.50 2.51 2.52 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |