mfc >> Setting non-rectangular clipping region without leaving gaps

by Erik Jevik » Wed, 22 Mar 2006 03:35:40 GMT

I have a rectangle with a 1px black border and rounded corners drawn
with CDC::RoundRect that I want to use as a clipping region. All
drawing and filling should happen within this rectangle. So I did:

dc.RoundRect(rectClient, CPoint(9, 9));
CRgn rgnClip;
rgnClip.CreateRoundRectRgn(rectClient.TopLeft().x + 1,
rectClient.TopLeft().y + 1,
rectClient.BottomRight().x,
rectClient.BottomRight().y,
9, 9);

If I don't add the +1 to the top-left coordinates, the clipping region
includes the left and top borders. However, with the 1 added, filling
operations miss out a handful of pixels in the top left and bottom left
corners.

How can I set a clipping region that corresponds exactly to the area
bounded by the rectangle borders?

Thanks,
Erik



Similar Threads

1. Rotate non-rectangular region

2. click on a non rectangular region

Hi,

I have a form with 2 region, not necessary rectangular region (most of the
time polygonal region).
If i click on region A, i want to run function A.
if i click on region B, i want to run function B.

but how can i detect a click on a region ?
how can i associate to this region a function to run in case of click on it
?

thanks,
Alain



3. How to get control clip region? - CSharp/C#

4. Modifying clip region

I'm trying to paint my own caption bar/title bar and also my own frame
border, but I'm having problems with modifying the clip region so
windows doesn't paint over my stuff when I call base.WndProc

I tried skipping base.WndProc alltogether, but it seems like the Menu
and Toolbar is part of the non client region and painted during
WM_NCPAINT and thus won't show up if base.WndProc is left out.

How do I modify the current clip region so windows won't repaint the
stuff I've already taken care of?

Below is the code taken from my Form

(NativeMethods contains all the [DllImport] stuff)

protected override void WndProc(ref Message m)
{
  switch(m.Msg)
  {
     case NativeMethods.WM_NCPAINT: //0x0085
       OnNCPaint(ref m, true);
       break;
     case NativeMethods.WM_NCACTIVATE://0x0086
       OnNCPaint(ref m, (m.WParam.ToInt32() == 0? false : true) ) ;
       break;
     default:
       break;
   }
   base.WndProc(ref m);
}

protected void OnNCPaint(ref Message m, bool active)
{
    IntPtr hDC = NativeMethods.GetWindowDC(m.HWnd);
    if (hDC.ToInt32() == 0)
    {
       return;
    }
    
    using(Graphics g = Graphics.FromHdc(hDC))
    {
       DrawBorder(g, active);
       DrawCaption(g, active);
       DrawIcon(g, active);

      // TODO modify the clip region so windows won't try and paint
      // over the stuff we just painted
     }
     m.Result = IntPtr.Zero;
     NativeMethods.ReleaseDC(m.HWnd,hDC);	
}

5. how do you change the size of the clipping region of a Graphics object - CSharp/C#

6. How to get clipping region of windowless activex?

How to get it without HWND?
If activex windowed i use GetRandomRgn(GDI) function,
and i want to get clipped region for windowless control the same as
GetRandomRgn do it for windowed.
How to do it?

7. Clipping Regions (Rects)

8. clipping region of a device context.

can someone explaing me what's a clipping region in a device context?
if i draw for example different circles in a window client area when i 
resize the window these objects disappear because the whole client area is 
invalidated by windows, so what represents the clipping region?The whole 
client area?
And what about

if(pDC->RectVisible(pElement->GetBoundRect()))//obtain enclosing shape rect
pElement->Draw(pDC); // ...draw it

this function checks if the enclosing rect of a shape, for example a circle, 
overlay the clipping region...what it exactly means?
Maybe th enclosing rect must be contained in the window client area that is 
invalidated?