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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With