The easiest way is to put the drawing code inside the WM_PAINT. Problem is that this will often slow down the painting and can cause flicker/shearing of the screen (unless the drawing is VERY simple).
Otherwise you need to 'double buffer' the drawing. This is creating a copy of the screen in memory and drawing this copy in response to a WM_PAINT msg.
When the app starts;
Create a DC compatible to the screen (CreateCompatibleDC) [lets call it memDC]
Create a bitmap compatible to the screen (CreateCompatibleBitmap) and the same size as the app window or PC screen resolution (see below).
SelectObject the bitmap into the memDC, saving the default bmp that is 'pushed' out.
Clean up any GDI objects (ie release any GetDC()'s).
When the screen changes;
Draw the changes to the memDC
Call for a paint msg (InvalidateRect() followed by UpdateWindow() )
When you get a paint msg
BitBlt the memDC to the the DC from the PAINTSTRUCT, using the rect from the PAINTSTRUCT (so we redraw the minimum amount and do all drawing in one call)
When the app changes size;
Clean up the DC and create a new one the correct size (OR create the compatible bmp the same size as the PC screen in the first place, instead of the app window size)
redraw to the new size
call for a paint
When your app closes;
SelectObject the default bmp back into the memDC
DeleteDC the memDC
DeleteObject the compatible bmp
I have posted code before if you need (try a search for 'double buffering').