Creating a Modeless Dialog Box with MFC LibrariesID: Q103788
|
class CModeless: public CDialog
{
.
.
.
public:
CModeless(){ }
BOOL Create(UINT nID, CWnd * pWnd)
{ return CDialog::Create(nID,pWnd);}
.
.
.
};
NOTE: You could let ClassWizard generate the dialog class and then
simply add the Create() function.
void CMainFrame::OnModeless()
{
pdlg = new CModeless;
pdlg->Create(IDD_DIALOG1,this);
}
where CMainFrame::pdlg is defined as:
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.
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 query words: kbinf 1.00 1.50 2.00 2.10 2.50 2.51 2.52 3.00 3.10 4.00
Keywords : kbMFC KbUIDesign kbVC
Version : WINDOWS:1.00,1.50,1.51,1.52; winnt:1.00,2.00
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: July 27, 1999