15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Prevent drawing out of bound

Jean Tu -- tu@cig.mot.com
Wednesday, December 04, 1996

Environment: NT 4.0, VC++ 4.2flat

Hi,

I have a picture control (rectangle) on a dialog, and I attached a
CStatic derived class
(just like the MFC sample Fire) to it. The picture control now is a
window and I will draw 
different graph on it. The window size is always 500x500, and the graph
generated at rum time can be bigger than 500x500, what I want is to have
the part which is bigger than 500x500 clipped. But now if I draw a
figure is bigger than 500x500, it will drawn on top of other
dialog controls.

How can I limit the drawing function only to draw with its own client
area?

Thanks,
-- 
Jean Tu			Motorola Celluar Infrastructure Group
Software Engineer	World Wide System Test Tools
(847) 632-2708		1501 W. Shure Drive     
tu@cig.mot.com		Arlington Heights, IL 60004



Mike Blaszczak -- mikeblas@nwlink.com
Saturday, December 07, 1996

[Mini-digest: 4 responses]

At 16:39 12/4/96 -0600, Jean Tu wrote:
>Environment: NT 4.0, VC++ 4.2flat

Please install the 4.2B patch. While it isn't germain to the problem
you're having right now, you will, eventually, come across something
that was fixed in 4.2B that you don't have because you haven't
installed it.

>The window size is always 500x500, and the graph
>generated at rum time can be bigger than 500x500, what I want is to have
>the part which is bigger than 500x500 clipped. But now if I draw a
>figure is bigger than 500x500, it will drawn on top of other
>dialog controls.

>How can I limit the drawing function only to draw with its own client
>area?

There are three ways to do this:

1) Do the clipping yourself.  If you realize that you're about to draw
out of bounds, don't. Sometimes, this is impractical--maybe you want
to draw a shape that starts in bounds but extends out of bounds and still
want to see the partial shape.

2) Ask Windows to do the clipping for you. Use the SelectClipRgn() member
of CDC.  Build a region from a single rectangle that matches the size of
your window.

3) Since you've subclassed a control, you might be able to use WS_CLIPCHI=
LDREN
or WS_CLIPSIBLINGS to have windows do #2 automatically for you.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.

-----From: jeremy@omsys.com (Jeremy H. Griffith)

On Wed, 04 Dec 1996 16:39:56 -0600, Jean Tu  wrote:

>How can I limit the drawing function only to draw with its own client
>area?

Use a clip region.  Here's code from OnDraw() of a graph class:

  // clip graph so that it doesn't overflow into text areas
  RECT clipRect =3D scrollRect;  // this defines the acceptable area
  if (!meta)                   // meta is true when drawing to a metafile
    pDC->LPtoDP(&clipRect);    //  which requires different handling here
  CRgn clipRgn;
  clipRgn.CreateRectRgnIndirect(&clipRect);
  if (!meta)=09
    pDC->SelectClipRgn(&clipRgn);
  // ...
  // draw image here
  // ...
  if (!meta)
    pDC->SelectClipRgn(NULL);  // unclip to permit text drawing
  clipRgn.DeleteObject();


--Jeremy
-----From: bibhas@isgtec.com (Bibhas Bhattacharya)

>=20
> How can I limit the drawing function only to draw with its own client
> area?
>=20
Set the window style to WS_CLIPCHILDREN | WS_CLIPSIBLINGS.

Bibhas.
bibhas@isgtec.com
-----From: "Alexander Grigoriev" 

Controls use parent DC for painting, thus no clipping is performed. You m=
ay
want to get another DC (through GetDCEx) that is not bound to the parent
dialog.

----------
> From: Jean Tu 
> To: mfc-l@netcom.com
> Subject: Prevent drawing out of bound
> Date: 5 =C4=C5=CB=C1=C2=D2=D1 1996 =C7. 1:39
>=20
> Environment: NT 4.0, VC++ 4.2flat
>=20
> Hi,
>=20
> I have a picture control (rectangle) on a dialog, and I attached a
> CStatic derived class
> (just like the MFC sample Fire) to it. The picture control now is a
> window and I will draw=20
> different graph on it. The window size is always 500x500, and the graph
> generated at rum time can be bigger than 500x500, what I want is to hav=
e
> the part which is bigger than 500x500 clipped. But now if I draw a
> figure is bigger than 500x500, it will drawn on top of other
> dialog controls.
>=20
> How can I limit the drawing function only to draw with its own client
> area?
>=20





| Вернуться в корень Архива |