I want to know how to restore objects that appear on window I will expalin in one Example;

Example (1)

case WM_COMMAND:
/////// Draw One Line
hdc=GetDC(hWnd);
MoveToEx(hd1,300,20,NULL);
LineTo(hd1,400,20);
ReleaseDC(hWnd,hd1);
/////////////////////////

My Problem Now is , if I the Application sends WM_PAINT message , I see the line is disappeared,
I know I can Draw the line under WM_PAINT message, But if I want to draw Line by using WM_COMMAND message , is thesr any tool to let me keep the objects on the window after application sent WM_PAINT Message.
I try to use InvalidateRect() function but It was not working..

Thanks & Regards