Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AfxMessageBox() not working...

82 views
Skip to first unread message

iceColdFire

unread,
May 11, 2005, 11:48:52 PM5/11/05
to
Hi,

Check out the code:::

int nResponse = dlg.DoModal();
switch(nResponse)
{
case IDOK:
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
AfxMessageBox("Exiting Application");
break;
}
case IDCANCEL:
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
AfxMessageBox("Exiting Application : Execution Cancelled");
break;
}
}// End Switch


Now here when the dialog ends, I dont see any message boxes popping
up...whats the issue...
Kindly suggest

Thanks,
a.a.cpp

Doug Harrison [MVP]

unread,
May 12, 2005, 12:11:39 AM5/12/05
to

The problem is that when an MFC app's main window is destroyed, MFC notices
this and posts WM_QUIT. AfxMessageBox calls MessageBox, whose message loop
retrieves WM_QUIT and returns immediately. There are a couple of ways
around this. The usual AppWizard-generated code is:

CMyDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

If you delete the line which assigns to m_pMainWnd, MFC won't post
WM_QUIT (and set m_pMainWnd to zero) when the dialog is destroyed.
However, it's nice to have a main window, so I leave it alone and make
a call to eat the WM_QUIT following DoModal:

MSG msg;
PeekMessage(&msg,0,WM_QUIT,WM_­QUIT,PM_REMOVE);

Now you can call MessageBox. See this KB article for another approach:

PRB: Windows Flash and Disappear in Dialog-Based Applications
http://support.microsoft.com/default.aspx?scid=kb;en-us;138681

--
Doug Harrison
Microsoft MVP - Visual C++

???

unread,
May 12, 2005, 2:59:27 AM5/12/05
to
try after adding 'default:' case.


"iceColdFire" <icol...@yahoo.com> wrote in message
news:1115869732.6...@g14g2000cwa.googlegroups.com...


> Hi,
>
> Check out the code:::
>
> int nResponse = dlg.DoModal();
> switch(nResponse)
> {
> case IDOK:
> {
> // TODO: Place code here to handle when the dialog is
> // dismissed with OK
> AfxMessageBox("Exiting Application");
> break;
> }
> case IDCANCEL:
> {
> // TODO: Place code here to handle when the dialog is
> // dismissed with Cancel
> AfxMessageBox("Exiting Application : Execution Cancelled");
> break;
> }

default:
AfxMessageBox("Another EndDialog()");

RainMan

unread,
May 12, 2005, 7:14:02 AM5/12/05
to
Follow this link. It contains some additional information to what Doug
already posted.
http://msdn.microsoft.com/newsgroups/managed/default.aspx?dg=microsoft.public.vc.mfc&mid=9ced1024-e78b-47f8-8165-a89ccd98c8b4
0 new messages