Here is a function to use in WM_PAINT
I have another HDC, exactly the same as the hdcScreen called hdcBuffer.
void RePaint(HWND hDlg,HDC hdcScreen)
GetUpdateRect(hWnd, &Rect, 0);
BitBlt(ps.hdc, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, hdcScreen, Rect.left, Rect.top, SRCCOPY);
All drawing is done to the hdcBuffer. When it is ready it is BitBlt'ed to the hdcScreen. The area draw is known and this is sent for painting using InvalidateRect(), calling the paint function above.
I keep the HWND, HDC's(screen and Buffer) ect in an array of structures. I use defined values to navigate thru the array. I set the initial values to NULL. I set them up in WM_CREATE for the dlg as needed and then check on close if they have been allocated and so free the resources.