2
votes

HI

I've created a window with rounded edges using the windows API calls CreateRoundRgn and SetWindowRgn however the rounded corners are not as smooth as say a rounded rectangle drawn with GDI+. Is there anyway to smooth out the window corners?

procedure TPBSDashboardPanel.DefineWindowRegion;
var
  WindowRegion: HRGN;
begin
  if Assigned(Parent) then
  begin
    WindowRegion := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);

    SetWindowRgn(Handle, WindowRegion, True);
  end;
end;
3

3 Answers

5
votes

If you wish to draw a themed rectangle, check this link. To render (semi) transparent bitmap, what (I guess) would be your aim, check out this function. For usage of both functions, let me know or inspire yourself using Google.

3
votes

Maybe use a bitmap with alpha transparency to simulate the anti-aliasing in addition to a slightly bigger rounded region for allowing Windows to do hit-testing.

The problem here is that the Win32 GDI uses regions for hit-testing so when drawn every point in a region has integer logical unit coordinates, so that when hit-tested it can be known to be either outside or inside the region.

God bless

PS: AFAIK there is no way of defining the actual region used by a window which would make the windows borders to be rendered with anti-aliasing, and Win32 only supports aliased windows. The WDM in Windows 7 blurs the borders but I think this is the shadow and not the actual region which is drawn blurred.

0
votes

I'm no expert on this, but I do know that GDI+ supports anti-aliasing, whereas GDI does not. Without anti-aliasing, rounded corners will not look smooth.