开发者

Smooth out rounded window corners

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 开发者_C百科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;


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜