Exclude a round rectangle from the clipping region?

What is the right way to exclude a round rectangle from gregion clipping using Delphi / GDI?

There is ExcludeClipRect to exclude the rectangular region and CreateRoundRectRgn along with SelectClipRgn to set the clipping region to a circular rectangle.

But how can I exclude the round rectangle from the clipping region (something like ExcludeClipRoundRect or ExcludeClipRgn)? I experimented with CombineRgn but didn't get it working.

+4
source share
2 answers

Thanks to the comment from @TLama, I was able to solve this as follows:

Region := CreateRectRgn (0, 0, ClientWidth, ClientHeight);
ExcludedRegion := CreateRoundRectRgn (1, 1, ClientWidth - 1, ClientHeight - 1, 3, 3);
CombineRgn (Region, Region, ExcludedRegion, RGN_XOR);
SelectClipRgn (Canvas.Handle, Region);

Previously, the problem was that the area that passed as the first parameter CombineRgnwas not created. In one of the sentences of the related tutorial, a hint is given:

One more thing to indicate that the destination region in CombineRgn may be one of the source areas.

along with this information from MSDN:

hrgnDest [in]: handle to the new area with dimensions determined by the union of the two other regions. (This area must exist before calling CombineRgn.)

+6
source

As an alternative to the already given answer , which will allow one smaller area to be determined, is to use ExtSelectClipRgn:

ExcludedRegion := CreateRoundRectRgn (1, 1, ClientWidth - 1, ClientHeight - 1, 3, 3);
ExtSelectClipRgn(Canvas.Handle, ExcludedRegion, RGN_DIFF);


, , reset ,

SelectClipRgn(Canvas.Handle, 0);

ExtSelectClipRgn.

+2

All Articles