1
HRGN hRgn1 = CreateRoundRectRgn(0,0,400,400,50,50); 
SetWindowRgn(hWnd, hRgn1, TRUE);

If I use this function directly, the window corners have a lot of aliasing, how Do I make it look smoother?

Or, it will need an image, but I wanted to realize it with the WindowDC(HBITMAP).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Use gdiplus. as it supports anti-aliasing. It doesn't have a native RoundRect function but you can get the same effect using a path. See e.g. https://stackoverflow.com/questions/67052759/c-gdi-how-to-draw-rectangle-with-border-radius – Jonathan Potter Oct 06 '21 at 04:57
  • I know that gdiplus could anti-aliasing,but how could I clip the window? – 末影小末EnderMo Oct 06 '21 at 06:46
  • I suggest you could refer to the thread: https://stackoverflow.com/questions/4425595/smooth-out-rounded-window-corners – Jeaninez - MSFT Oct 06 '21 at 07:54
  • Regions cannot be anti-aliased, only a monitor with a higher dpi could make it look better. One of the reasons why SetWindowRgn() is rarely used. – Hans Passant Oct 06 '21 at 09:08
  • Sorry I missed that you wanted it for a window region. You can't do it. Use `UpdateLayeredWindow()` instead. – Jonathan Potter Oct 06 '21 at 10:05
  • Could you give me a UpdateLayeredWindow() example with round rect ergion?thank you! – 末影小末EnderMo Oct 06 '21 at 12:45
  • Layered windows support per-pixel alpha transparency. You'll have to render the corner radius using a method that supports anti-aliasing. Since GDI doesn't you'll have to consider using another library, like GDI+. – IInspectable Oct 06 '21 at 12:55
  • I have already made an GDI+ rounded rect function,but how to change it into region? – 末影小末EnderMo Oct 06 '21 at 13:05
  • @末影小末EnderMo "*how to change it into region?*" - you don't, that is the whole point. You wouldn't use a region *at all* in this situation. A Layered window has its own native transparency/translucency, so there is no need for a region. Simply create the window using a bitmap that has an alpha channel to mask out the corner pixels you don't want rendered opaguely. – Remy Lebeau Oct 06 '21 at 16:26
  • I already make a function to change a gdi bitmap to function,but it need to use gdi+ for the anti-aliasing now,that is the problem – 末影小末EnderMo Oct 07 '21 at 10:42

0 Answers0