Discussion:
how to limit the plot in Client area while handling WM_PAINT?
(too old to reply)
BruceWho
2006-12-05 14:26:47 UTC
Permalink
Hi, all

I add my own code in OnPaint() of a static control and want to draw
something(e.g. sin wave) but I find that some part of the plot goes out
of the static control area. But If I draw it with CClientDC in
functions other than OnPaint() plot never goes out of the static
control.

Could anybody tell how to make only the part of plot in static control
be drawn? I just donnot want to caculate if each point/curve is in or
out of the static control.

Any help would be appreciated!

Bruce
David Ching
2006-12-05 14:36:06 UTC
Permalink
Post by BruceWho
Hi, all
I add my own code in OnPaint() of a static control and want to draw
something(e.g. sin wave) but I find that some part of the plot goes out
of the static control area. But If I draw it with CClientDC in
functions other than OnPaint() plot never goes out of the static
control.
Could anybody tell how to make only the part of plot in static control
be drawn? I just donnot want to caculate if each point/curve is in or
out of the static control.
Any help would be appreciated!
Bruce
Is there a reason you're using CClientDC to paint outside of the OnPaint()
method? Please note that anything you paint like this will become erased if
your window is covered by another window, then uncovered. That's because
Windows calls your OnPaint() when the window is uncovered, and the code you
used with the CClientDC isn't run.

But regardless, there should be no difference. Either way, in OnPaint() or
outside of it, I think you would do a GetClientRect() and scale your sine
wave accordingly. That should keep it within the bounds of your static
control. Are you doing GetClientRect()?

-- David
Michael K. O'Neill
2006-12-05 16:24:29 UTC
Permalink
Post by David Ching
Post by BruceWho
Hi, all
I add my own code in OnPaint() of a static control and want to draw
something(e.g. sin wave) but I find that some part of the plot goes out
of the static control area. But If I draw it with CClientDC in
functions other than OnPaint() plot never goes out of the static
control.
Could anybody tell how to make only the part of plot in static control
be drawn? I just donnot want to caculate if each point/curve is in or
out of the static control.
Any help would be appreciated!
Bruce
Is there a reason you're using CClientDC to paint outside of the OnPaint()
method? Please note that anything you paint like this will become erased if
your window is covered by another window, then uncovered. That's because
Windows calls your OnPaint() when the window is uncovered, and the code you
used with the CClientDC isn't run.
But regardless, there should be no difference. Either way, in OnPaint() or
outside of it, I think you would do a GetClientRect() and scale your sine
wave accordingly. That should keep it within the bounds of your static
control. Are you doing GetClientRect()?
-- David
In your OnPaint() function, how are you getting your device context?

If you get it from a CPaintDC, then it would be impossible for you to draw
outside the window. Try using CPaintDC, if you are not using it already.
Loading...