Alex Sokolek
Member
- Joined
- Apr 5, 2024
- Messages
- 44
- Thread Author
- #1
Hi. I'm having trouble with PeekMessage(). I use PeekMessage() in a loop inside my WM_PAINT procedure to consume messages generated during a long computation process, and to allow the user to abort the process by pressing ESCAPE. Here is a snippet of my code...
I used OutputDebugString() to display the message code and wparam values. I never get a WM_KEYDOWN message (0x0100). I should, when I press ESCAPE during the lengthy execution. Any ideas? Thanks.
Code:
... 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
I used OutputDebugString() to display the message code and wparam values. I never get a WM_KEYDOWN message (0x0100). I should, when I press ESCAPE during the lengthy execution. Any ideas? Thanks.