views:

339

answers:

3

I'm trying to create a Win32 window that has rounded corners and is resizable both horizontally and vertically. My first approach was to create BITMAP of a rounded rectangle and draw it to the screen in conjunction with setting the windows style to WS_EX_LAYERED and setting the transparency key to the outside color of the rounded rectangle.

This works, but it only looks good if the window is a fixed size. If I allow the user the resize the window and stretch the bitmap along with it, the rounded corners look stretched out, too. Is there a way to create a window that has nice, smooth rounded corners and is resizable in windows? Eventually, I would also like to add a drop shadow to the window as well.

+2  A: 

I would try to mix the Windows API functions CreateRoundRectRgn and SetWindowRgn. A very simple example can be found at pInvoke.net web site.

Carlos Loth
+1  A: 

Instead of drawing the corner with a pre-existing bitmap, you'll want/need to draw an ellipse (or whatever) in the correct shape, then composite that to the screen. For example, you might decide on an ellipse with each radius being 5% of the window size in that direction.

Jerry Coffin
A: 

You can create a window without any frame, use WS_EX_LAYERED to get transparency, then either draw the window including your custom frame "normally" in WM_PAINT, or you compose an off-screen bitmap, and use UpdateLayeredWindow (the latter method is more efficient).

You have to adjust what you draw to the current size of the window, of course. Typically, you would compose it from different elements - e.g. use four "corner" bitmaps (or an ellipse function) to draw the corners, then draw the border, etc.

Also, you can handle WM_NCHITTEST to assign "title" / "border" / "corner" functionality (i.e. moving and sizing the window) to arbitrary areas of your window.

peterchen