HOW to save DC of onpaint(); in SDI MFC C++?
-
how i can save dc of onpaint in MFC SDI c++? when i draw a rectangle with mouse,i can draw only on rectangle at a time??: confused:
You shouldn't save the dc. If you need to paint multiple rectangles then do draw multiple rectangles in a single
OnPaint
body. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
You shouldn't save the dc. If you need to paint multiple rectangles then do draw multiple rectangles in a single
OnPaint
body. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
You must NOT save (or load) the device context. On the other hand, you must save the state of your drawing. For instance, once a rectangle has been draw (on mouse action) you should save it somewhere in you class. Whenever the
OnPaint
call occurs you have to redraw all the saved rectangles. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
You must NOT save (or load) the device context. On the other hand, you must save the state of your drawing. For instance, once a rectangle has been draw (on mouse action) you should save it somewhere in you class. Whenever the
OnPaint
call occurs you have to redraw all the saved rectangles. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
okay but which functions i have to use to save the state of rectangles....plzz tell me the complete way..
There's no function to do such a thing. You have to store all the rectangle information in a container (like for instance a std::list). If you don't know what a std::vector is, it is a kind of array of objects but which can grow dynamically. It is much easire to work with than C arrays. So, the principle is: once you moved the mouse to show an additional rectangle, instead of drawing it directly, you create an instance of your rectangle class and you add it to the vector, then you call Invalidate() in your view, which will force a redraw of the view. In the OnPaint method, you simply iterate over all your elements in your vector and draw them one by one.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
okay but which functions i have to use to save the state of rectangles....plzz tell me the complete way..
Cédric gave you the solution: after mouse action, store the (new) rectangle coordinates into an 'array of rectangle coordinates' (as suggested you may better use a STL container as the
std::vector
) and call in sequenceInvalidateRect
,UpdateWindow
(to make re-paint happen), Inside theOnPaint
message handler draw all the rectangles of the array. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Cédric gave you the solution: after mouse action, store the (new) rectangle coordinates into an 'array of rectangle coordinates' (as suggested you may better use a STL container as the
std::vector
) and call in sequenceInvalidateRect
,UpdateWindow
(to make re-paint happen), Inside theOnPaint
message handler draw all the rectangles of the array. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]