Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude round rectangle from clipping region?

What's the correct way to exclude a round rectangle from the clipping gregion with Delphi / GDI?

There is ExcludeClipRect to exclude a rectangular region and there is CreateRoundRectRgn together with SelectClipRgn to set the clipping region to a round rectangle.

But how can I exclude a round rectange from the clipping region (something like ExcludeClipRoundRect or ExcludeClipRgn)? I experimented with CombineRgn but did not get it working.

like image 504
jpfollenius Avatar asked Feb 15 '23 17:02

jpfollenius


1 Answers

Thanks to the comment by @TLama I was able to solve it like this:

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);

The problem before was that the region passed as the first parameter to CombineRgn has not been created. One sentence from the linked tutorial provided the clue:

One more thing to point out is that the destination region in CombineRgn can be one of the source regions.

together with this information from MSDN:

hrgnDest [in]: A handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn is called.)

like image 145
jpfollenius Avatar answered Feb 23 '23 07:02

jpfollenius