... Create several threads to do some lengthy work
// Wait for all threads to terminate.
for (;;)
{
// Wait for up to fifty milliseconds.
if (WaitForMultipleObjects(Threads, phThreadArray, TRUE, 50) == WAIT_OBJECT_0) break;
// Update the user about progress.
int Slice = wq->getSlices();
int iPercent = (int)((Slices - Slice) * 100.f / Slices + 0.5f);
StringCchPrintf(szProgress, 100, _T("Slice: %d of %d (%d%%)"), Slices - Slice, Slices, iPercent);
SetBkColor(dc, RGB(240, 240, 240));
TextOut(dc, 16, 16, szProgress, lstrlen(szProgress));
TextOut(dc, 16, 40, _T("Press ESC to abort"), 19);
// Flush the message queue and check for abort request.
MSG msg;
if (!PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)) continue; // Case of no message.
TCHAR sz[50];
StringCchPrintf(sz, 50, _T("%08x %016x\n"), msg.message, msg.wParam);
OutputDebugString(sz);
if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) bAbort = true;
}
... Clean up and display results