yytg wrote:
I tried to imitate the function DoEvents as so
yytg wrote:
But when I call the functions - it's not working... How do I do it in C++
I've had a need to implement DoEvents in C++ myself, and wrote something that works. Here is what I came up with.
namespace
{
void DoEventsPumpMessage()
{
CWinThread *pThread = AfxGetThread();
if( !pThread->PumpMessage() )
{
int nResult = (int)AfxGetCurrentMessage()->wParam; // value from PostQuitMessage
::PostQuitMessage(nResult); // so the main message loop will get it.
TRACE("DoEvents Received quit message\n");
CQuitMessageException::Throw();
}
}
}
void DoEvents( bool bAtLeastOne )
{
if( bAtLeastOne )
{
DoEventsPumpMessage();
}
MSG message;
while( ::PeekMessage( &message, NULL, 0, 0, PM_NOREMOVE ) )
{
DoEventsPumpMessage();
}
}
Many message loops I've seen just assume there won't be a quit message, but in my case, I really wanted to avoid runaway background threads. Nathan