[Quest] How to restore Objects of Window after WM_PAINT Message
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
Re: [Quest] How to restore Objects of Window after WM_PAINT Message
The only one reliable place to draw something in window client area, is under WM_PAINT message.
From any another place (e.g. from a command message) call InvalidateRect or RedrawWindow.
That didn't work for you most possible because a mistake in your code.
Re: [Quest] How to restore Objects of Window after WM_PAINT Message
Thanks oviducucu,
And I hope to find solution ,
My Question is : How to get the content of window (Lines and dots) and restore it again after sending WM_PAINT message
I hope Igor will provide us his effective answers..
Re: [Quest] How to restore Objects of Window after WM_PAINT Message
The main principle: window must be able to redraw itself at any moment of its life.
This means:
- application should support Model approach: a number of data structures containing every entity information at least in aspect of drawing. Typically this is implemented as a polymorphic class hierarchy for drawing primitives/shapes/sprites. The drawing primitive instances appear stored in containers of an appropriate type
- application should support View approach: a rendering logic able to proceed based on the Model data. Typically this rendering occurs in response to every WM_PAINT message.
- application should support Controller approach: a logic for changing Model data in response to input from user or any other source of events. Typically Controller is comprised of a number of message handlers performing changes to Model and initiating window self redraw by means of InvalidateRect. Ideally this should be a single per-window class implementing controlling logic.
In accordance with this MVC approach you have your drawing not scattered all over the window procedure but being neatly structured and reliably tidy.
Re: [Quest] How to restore Objects of Window after WM_PAINT Message
See this post as a demo for the approach above.
Re: [Quest] How to restore Objects of Window after WM_PAINT Message
Thanks Igor for your proffesional answers ;