Thanks for reaching out!
Here are some fixes you can try
1.Paint only in WM_PAINT. In input handlers (mouse/timer), update state and call InvalidateRect
2.Always pair APIs correctly.
BeginPaint and EndPaint ,also GetDC and ReleaseDC,
CreateCompatibleDC/CreatePen/CreateBrush/CreateFont and DeleteDC/DeleteObject.
3.Never delete a selected object. Save the old object from SelectObject(hdc, newObj), then re-select it back before DeleteObject.
4.Draw everything into the memory DC, then BitBlt it to the paint DC in WM_PAINT.
Try these quick debugging steps
1.Run with GDI object count visible. If it climbs continuously, you’re leaking.
2.Temporarily assert that every SelectObject returns non-NULL and that you re-select the original object before DeleteObject.
3.Verify you never call DeleteDC on an HDC from BeginPaint/GetDC.
4.If you ever see black/white frames: check where you call CreateCompatibleBitmap ensure it uses a screen DC.