I put TimedMessageBox code from MSDN in my code. When the MessageBox disappears, so is the MFC application, while it stays in place (does not quit MFC) if I replace it with ordinary MessageBox. How can I make the MFC application stay in place using this TimedMessageBox ?

This is the code:

//////////////////////////////////
//// MessageBoxTimer From MSDN
//////////////////////////////////

void CALLBACK
MessageBoxTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
{
PostQuitMessage(0);
}

UINT TimedMessageBox( HWND hwndParent,LPCTSTR ptszMessage,LPCTSTR ptszTitle,
UINT flags, DWORD dwTimeout)
{
UINT idTimer;
UINT uiResult;
MSG msg;

idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer);

uiResult = MessageBox(hwndParent, ptszMessage, ptszTitle, flags);

KillTimer(NULL, idTimer);

/* See if there is a WM_QUIT message in the queue. */

if (PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE))
{
uiResult = 0;
}

return uiResult;
}