Reopening a modal dialog in MFC

I need to open a dialog box created from the same class twice. When i try this

CdelmeDlg dlg;
dlg.DoModal();
dlg.DoModal();

The second call opens the dialogue only for a split second, then it closes. My bet was that there is a message remaining in the message queue, so I added this between calls

MSG msgCur;
while (::PeekMessage(&msgCur, NULL, NULL, NULL, PM_REMOVE))
    ;

This solves the problem, but it seems like the wrong thing. Is there a way to properly handle the remaining message?

+5
source share
6 answers

Do not call EndDialog (IDOK);

To process the pressed ok or cancel buttons, simply inherit OnOk or OnCancel ... Otherwise, EndDialog is called twice and you get the problem you get!

+1

, YeenFei .

, MFC ( ), , , , . , , , , , . , , .

, YeenFei , , , , , . , , , , - , .

(www.eggheadcafe.com) concurrency, , , , .

+1

:

CdelmeDlg dlg; 
dlg.DoModal(); 

CdelmeDlg dlg1; 
dlg1.DoModal(); 
+1

, , juz ? this- > ShowWindow (SW_HIDE) .

, , , , .

0

, , , , .

0

, :

m_pMainWnd = &dlg;

, DoModal() , DoModal() -1. MSDN:

Microsoft Foundation , , m_pMainWnd, . , .

0

All Articles