I'm building a Win32 application and need to update the window in response to user input. Whether I use UpdateWindow() or RedrawWindow(), the contents sometimes flicker for about a second, which makes the interface feel rough. What is the proper way to repaint the window without showing that brief background erase or redraw? I'm still learning Win32, so practical guidance would be appreciated.
2 Answers
For more complex drawing, use double buffering. Create a memory device context and compatible bitmap, draw the complete frame off screen, and then copy it to the window with BitBlt in one operation. Afterward, restore the original bitmap, delete the temporary bitmap, and release the memory DC so you don’t leak GDI handles. This prevents the user from seeing the intermediate erase and drawing steps.
The flicker is often caused by Windows erasing the background before your painting code runs. Handle WM_ERASEBKGND yourself and return 1, then paint the entire background during WM_PAINT. You can also avoid requesting an erase: use InvalidateRect(hwnd, NULL, FALSE), or leave RDW_ERASE out when calling RedrawWindow().
This works well when your WM_PAINT handler redraws every part of the client area, since you’re taking responsibility for the background yourself.

Double buffering is usually the most reliable long-term solution for custom Win32 drawing, especially when several controls or graphics are updated together.