I'm getting several WM_PAINT
messages/events in the message handler for my window while I resize it, even though I only translate+dispatch a single message.
Is this normal? Why is this happening? (I was expecting to get one WM_PAINT message per dispatch, and never more than that)
Window loop:
while (true) // only for the example
{
std::cout << "Checking events\n";
MSG winEvent = {};
while (PeekMessage(&winEvent, NULL, 0, 0, PM_REMOVE))
{
std::cout << "ev\n";
TranslateMessage(&winEvent);
DispatchMessage(&winEvent);
}
}
Message handler function:
LRESULT CALLBACK windowEvent(HWND _hwnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam)
{
switch (_uMsg)
{
// extra cases removed for the example
case WM_PAINT:
std::cout << "PAINT EVENT\n";
return DefWindowProc(_hwnd, _uMsg, _wParam, _lParam);
}
return DefWindowProc(_hwnd, _uMsg, _wParam, _lParam);
}
Console output:
- prior to clicking, many "checking events" and "ev" messages appear
- when first clicking on the border of the window, "ev" appears
- while holding left click, no messages appear
- when holding and dragging to make the window bigger, more "PAINT EVENT" messages appear
Checking events
ev
PAINT EVENT
PAINT EVENT
PAINT EVENT
PAINT EVENT
PAINT EVENT
PAINT EVENT
PAINT EVENT
PAINT EVENT