From: Joseph M. Newcomer on
See below...
On Thu, 22 Oct 2009 06:01:27 -0700 (PDT), Luigino <npuleio(a)rocketmail.com> wrote:

>OK it looks like now I figured out about to draw a black background
>with a green grid inside an OnDraw() event.
>Since I want to initialize the control inside creation method,
****
Probably a Bad Idea. You may not ever *get* a creation notification, for example, if you
were to simply give the control class and style flags at dialog editing time. If you need
to do initialization, you would do it in PreSubclassWindow
****
>I
>supposed to start getting the DC since, as I did before in OnDraw(), I
>know calling "CPaintDC dc(this);" means performing a BeginPaint and
>EndPaint...
>So I did:
>
>CMemDC MemDC(this->GetDC());
>CRect rect;
>GetClientRect(rect);
****
You are confusing drawing with "initialization". There is no reason to ever, ever do this
during creation time; the OnDraw will handle initial drawing. THere is no reason to do
GetDC(); the correct way to get a DC for a window is
CClientDC(this);
but why do you need it? Doing drawing outside the OnDraw handler makes no sense!
****
>
>then the rest of the code to fillrect a black rectangle as background,
>selecting a pen to draw all those lines with MoveTo and LineTo....and
>I commented the OnDraw() because this background has to be drawn in my
>own CCreate event. Obviously I called the Create method properly of
>CWnd and SetWindowPos() and the result is that it doesn't draw
>anything... (no errors and in debug it executes this code
>correctly)...
****
It never, ever, under any circumstances makes sense to do any drawing in your OnCreate
handler. You completely miss the point of how drawing is done. The ONLY place you would
do drawing is in your OnDraw handler. Period. If you are doing drawing in your OnCreate
(or PreSubclassWindow) handler, your design is wrong, and you have to fix it. You fix it
by removing all the drawing code from those places. Assume that if you have drawing code
in either place, your code is simply wrong.

(There are VERY RARE exceptions, such as doing rubber-banding in OnMouseMove, but they are
very rare exceptions. Any time you would think that doing drawing in OnCreate or
PreSubclassWindow is another such exception, you are guaranteed that such a choice is
wrong. And just about any other choice to draw outside OnDraw is wrong, again, with very
rare exceptions. But until you master the concept of the fact that OnDraw is where you do
the drawing, DO NOT assume you have a clue about any drawing outside this as being valid.
Instead, assume that it is not valid to draw outside OnDraw. This is the safest approach
for a beginner)
****
>
>Maybe I shall call some instruction to force drawing on the context as
>initialization?....
****
Your OnDraw handler draws the content of the window. If there is nothing to draw, it may
take some special action, but otherwise, you can assume that any drawing done outside
OnDraw (with the very rare exceptions, none of which you have here) is wrong.
joe
****
>
>Thanks to everyone!!!
>Ciao Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Luigino on
> ****
> Probably a Bad Idea. You may not ever *get* a creation notification, for example, if you
> were to simply give the control class and style flags at dialog editing time. If you need
> to do initialization, you would do it in PreSubclassWindow
> ****>I
> You are confusing drawing with "initialization". There is no reason to ever, ever do this
> during creation time; the OnDraw will handle initial drawing. THere is no reason to do
> GetDC(); the correct way to get a DC for a window is
> CClientDC(this);
> but why do you need it? Doing drawing outside the OnDraw handler makes no sense!
> ****
> ****
> It never, ever, under any circumstances makes sense to do any drawing in your OnCreate
> handler. You completely miss the point of how drawing is done. The ONLY place you would
> do drawing is in your OnDraw handler. Period. If you are doing drawing in your OnCreate
> (or PreSubclassWindow) handler, your design is wrong, and you have to fix it. You fix it
> by removing all the drawing code from those places. Assume that if you have drawing code
> in either place, your code is simply wrong.
>
> (There are VERY RARE exceptions, such as doing rubber-banding in OnMouseMove, but they are
> very rare exceptions. Any time you would think that doing drawing in OnCreate or
> PreSubclassWindow is another such exception, you are guaranteed that such a choice is
> wrong. And just about any other choice to draw outside OnDraw is wrong, again, with very
> rare exceptions. But until you master the concept of the fact that OnDraw is where you do
> the drawing, DO NOT assume you have a clue about any drawing outside this as being valid.
> Instead, assume that it is not valid to draw outside OnDraw. This is the safest approach
> for a beginner)
> ****
> Your OnDraw handler draws the content of the window. If there is nothing to draw, it may
> take some special action, but otherwise, you can assume that any drawing done outside
> OnDraw (with the very rare exceptions, none of which you have here) is wrong.


HI Joe!!

You're right.... in fact right before I read this reply last friday I
figured, with some code tests, OnDraw is the only way to make drawing
stuffs, even at inizialization...just it will draw the initial state
and refresh it till I "send" changes to the layout...
Now I'm trying to study a class-style implementation of bars and
lines to draw on the DC, which isn't really easy since I want also to
"rotate"-left the background grid I draw... I guess I'll have to use
some incremental/decremental variables to pass to the for(...)
iterator so at every repaint it would do a sense of rotation, maybe it
is the only way...
But as you know, to draw lines and bars, the only way is to use MoveTo
and LineTo/Rectangle instructions to draw them, right?... Or are there
some functions that would draw lines and bars in function of
values?...

Thanks!!

Ciao,
Luigi
From: Joseph M. Newcomer on
See below...
On Mon, 26 Oct 2009 04:06:10 -0700 (PDT), Luigino <npuleio(a)rocketmail.com> wrote:

>> ****
>> Probably a Bad Idea. You may not ever *get* a creation notification, for example, if you
>> were to simply give the control class and style flags at dialog editing time. If you need
>> to do initialization, you would do it in PreSubclassWindow
>> ****>I
>> You are confusing drawing with "initialization". There is no reason to ever, ever do this
>> during creation time; the OnDraw will handle initial drawing. THere is no reason to do
>> GetDC(); the correct way to get a DC for a window is
>> CClientDC(this);
>> but why do you need it? Doing drawing outside the OnDraw handler makes no sense!
>> ****
>> ****
>> It never, ever, under any circumstances makes sense to do any drawing in your OnCreate
>> handler. You completely miss the point of how drawing is done. The ONLY place you would
>> do drawing is in your OnDraw handler. Period. If you are doing drawing in your OnCreate
>> (or PreSubclassWindow) handler, your design is wrong, and you have to fix it. You fix it
>> by removing all the drawing code from those places. Assume that if you have drawing code
>> in either place, your code is simply wrong.
>>
>> (There are VERY RARE exceptions, such as doing rubber-banding in OnMouseMove, but they are
>> very rare exceptions. Any time you would think that doing drawing in OnCreate or
>> PreSubclassWindow is another such exception, you are guaranteed that such a choice is
>> wrong. And just about any other choice to draw outside OnDraw is wrong, again, with very
>> rare exceptions. But until you master the concept of the fact that OnDraw is where you do
>> the drawing, DO NOT assume you have a clue about any drawing outside this as being valid.
>> Instead, assume that it is not valid to draw outside OnDraw. This is the safest approach
>> for a beginner)
>> ****
>> Your OnDraw handler draws the content of the window. If there is nothing to draw, it may
>> take some special action, but otherwise, you can assume that any drawing done outside
>> OnDraw (with the very rare exceptions, none of which you have here) is wrong.
>
>
>HI Joe!!
>
>You're right.... in fact right before I read this reply last friday I
>figured, with some code tests, OnDraw is the only way to make drawing
>stuffs, even at inizialization...just it will draw the initial state
>and refresh it till I "send" changes to the layout...
>Now I'm trying to study a class-style implementation of bars and
>lines to draw on the DC, which isn't really easy since I want also to
>"rotate"-left the background grid I draw... I guess I'll have to use
>some incremental/decremental variables to pass to the for(...)
>iterator so at every repaint it would do a sense of rotation, maybe it
>is the only way...
****
Not sure what you mean by "rotate" left; do you mean actual rotation around an axis, so
the graph is drawn either horizontall or vertically? Please clarify
****
>But as you know, to draw lines and bars, the only way is to use MoveTo
>and LineTo/Rectangle instructions to draw them, right?... Or are there
>some functions that would draw lines and bars in function of
>values?...
****
Lines can be done with PolyLine and PolyPolyLine, among other techniques (and will go much
faster if you have a lot of line segments, such as on a continuous line graph!) Bars are
done by the Rectangle call.
joe
****
>
>Thanks!!
>
>Ciao,
>Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Luigino on
HI again Joe,

> Not sure what you mean by "rotate" left; do you mean actual rotation around an axis, so
> the graph is drawn either horizontall or vertically? Please clarify

Yes I meant rotation around an axis like when looking at Process
Manager graph where it rotates, drawing new values at right side of
the graph...

> Lines can be done with PolyLine and PolyPolyLine, among other techniques (and will go much
> faster if you have a lot of line segments, such as on a continuous line graph!) Bars are
> done by the Rectangle call.

PolyLine/PolyPolyLine...ok... I'll get a study on these
instructions... thanks Joe!

Ciao
Luigi
From: Joseph M. Newcomer on
Actually, that is not "rotating", that is "sliding". So all you need to do is maintain an
origin value and redraw from the origin.

For optimization, you can use ScrollWindow to scroll the existing material to the left,
which will create a gap on the right, and the OnDraw will only actually write to the gap,
thus reducing apparent flicker.
joe

On Mon, 26 Oct 2009 08:37:22 -0700 (PDT), Luigino <npuleio(a)rocketmail.com> wrote:

>HI again Joe,
>
>> Not sure what you mean by "rotate" left; do you mean actual rotation around an axis, so
>> the graph is drawn either horizontall or vertically? Please clarify
>
>Yes I meant rotation around an axis like when looking at Process
>Manager graph where it rotates, drawing new values at right side of
>the graph...
>
>> Lines can be done with PolyLine and PolyPolyLine, among other techniques (and will go much
>> faster if you have a lot of line segments, such as on a continuous line graph!) Bars are
>> done by the Rectangle call.
>
>PolyLine/PolyPolyLine...ok... I'll get a study on these
>instructions... thanks Joe!
>
>Ciao
>Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm