Jeff Prosise beschreibt in 'Programming Windows with MFC' eine Möglichkeit
This problem is easily solved with a message pump. Here's the proper way to execute a lengthy procedure in a single-threaded MFC program:
void CMainWindow::OnStartDrawing ()
{
m_bQuit = FALSE;
for (int i=0; i<NUMELLIPSES && !m_bQuit; i++) {
DrawRandomEllipse ();
if (!PeekAndPump ()) // PeekAndPump entspricht DoEvents
break;
}
}
void CMainWindow::OnStopDrawing ()
{
m_bQuit = TRUE;
}
BOOL CMainWindow::PeekAndPump ()
{
MSG msg;
while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!AfxGetApp ()->PumpMessage ()) {
::PostQuitMessage (0);
return FALSE;
}
}
LONG lIdle = 0;
while (AfxGetApp ()->OnIdle (lIdle++));
return TRUE;
}
PeekAndPump enacts a message loop within a message loop. Called at the conclusion of each iteration through OnStartDrawing's for loop, PeekAndPump first calls CWinThread::PumpMessage to retrieve and dispatch messages if ::PeekMessage indicates that messages are waiting in the queue. A 0 return from PumpMessage indicates that the last message retrieved and dispatched was a WM_QUIT message, which calls for special handling because the application won't terminate unless the WM_QUIT message is retrieved by the main message loop. That's why PeekAndPump posts another WM_QUIT message to the queue if PumpMessage returns 0, and why the for loop in OnStartDrawing falls through if PeekAndPump returns 0. If a WM_QUIT message doesn't prompt an early exit, PeekAndPump simulates the framework's idle mechanism by calling the application object's OnIdle function before returning.
funktioniert prinzipiell, habe es auch schon mal verwendet, kann aber je nach verwendung etwas umständlich werden. ich weiß nicht, ob sich dein problem so lösen lässt. vielleicht solltest du über einen worker thread nachdenken.