Basically you're posting a WM_PAINT message with InvalidateRect, however you are still doing stuff in a loop so the message isn't being processed. If this is in another thread then the code would probably work.