Reputation: 16620
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.
Upvotes: 4
Views: 1038
Reputation: 54822
As an alternative to the already given answer, which will allow to define one less region, is to use ExtSelectClipRgn
:
ExcludedRegion := CreateRoundRectRgn (1, 1, ClientWidth - 1, ClientHeight - 1, 3, 3);
ExtSelectClipRgn(Canvas.Handle, ExcludedRegion, RGN_DIFF);
If you're not sure that the clipping region has been unmodified before or not, and want to reset the region, you can call
SelectClipRgn(Canvas.Handle, 0);
before calling ExtSelectClipRgn
.
Upvotes: 2
Reputation: 16620
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.)
Upvotes: 6