Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reopen modal dialog in MFC

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

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

The second call opens the dialog only for a split second, then it is closed. My bet was there is a leftover message in the message queue, so I added this in between the calls

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

This solves the problem, but it feels like a wrong kind of thing to do. Is there a way to process the leftover message properly?

like image 218
MMx Avatar asked Oct 25 '22 23:10

MMx


1 Answers

Don't call EndDialog( IDOK );

To handle the ok or cancel buttons being pressed just inherit OnOk or OnCancel ... Otherwise EndDialog is going to be called twice and you'll get the problem you are getting!

like image 51
Goz Avatar answered Oct 28 '22 13:10

Goz