The window does not have a persistent canvas/bitmap associated with its surface. The system can overwrite a protion of your window on the screen any time, and it can call you any time with a WM_PAINT to ask you to redraw the 'destroyed' part of the window image on the screen.
The drawing consists of 2 steps:
- The system sends WM_ERASEBKGND to your window/control.
- WM_PAINT, where you have to draw your control
If you want to keep the image of your window/control then you have to draw the actual appearance of the control to an in-memory bitmap, and in the WM_PAINT message you just draw the bitmap to the control. This is called double buffering. If the control is not too complex then it does not worth keeping an in memory bitmap for this purpose. Doublebuffering is usually used only if the drawing of the control is complex and performance critical, or if you can avoid a lot of annoying flickering. Another two flicker avoidance methods:
- Returning 1 from WM_ERASEBKGND without clearing the beckground before painting.
- Moving your drawing to WM_ERASEBKGND entirely from your WM_PAINT, and doing nothing in WM_PAINT but validating the clipping region (for example by just calling BeginPaint() and EndPaint() without actual drawing).