Changing a Window's Shape
In reality changing window's shape is very easy to do, although most people think that it's an extremely hard procedure. In this article I will explain how to create a window that will be a circle instead of a rectangle shape.
There are two functions that change window's shape: CWnd::SetWindowRgn() and win32's SetWindowRgn(). I will use the CWnd::SetWindowRgn(), but u can use the one you like more.
The function declaration looks like this:
int SetWindowRgn( HRGN hRgn, BOOL bRedraw );
The return value is zero if function fails or nonzero otherwise(at least it says so in Microsoft documentation). The first parameter is the CRgn, a region of a window, and the second parameter is a BOOL value that allows u to redraw the window. All you have to do is to create a CRgn variable, and pass the parametr to the SetWindowRgn function. That's all.
Here is the source code you have to add to your application in order to make a window be a circle shape.
CRgn MyRgn; MyRgn.CreateEllipticRgn(0, 0, 100, 100); SetWindowRgn(MyRgn, TRUE);
That's it. I can add just one more thing. If you create a button or another window without a title bar, you can skip this paragraph. If the window has a title bar, I advise you to read this. The thing is, that with most regions at least part of a title bar will not be drawn. From my point of view, the optimal decision is to create a window with a style that won't have a title bar, and then implement the title bar functions yourself. It sounds hard, but it's much easier then dealing with a regular title bar.

Comments
READ THIS
Posted by Legacy on 07/11/2002 12:00amOriginally posted by: Nitin S. Jadhav
Hi,
ReplyI was searching for a article on how to create non-rectangular window that can be resized and found the following pdf document.
http://www.ratedog.com/cpp/nonrect.pdf
You will definitely like this.
nitin
SetWindowRgn() works only once
Posted by Legacy on 11/22/2001 12:00amOriginally posted by: B Srinivasa reddy
I am trying to set the Roundrect region for a CStatic control using SetWindowRgn() in order to set rounded bmp in the control. SetWindowRgn() works properly for the first time, but the second time when is call the same function again in the On Paint function the controls comes up with the orginal rect
Please let me know if there is any solution or work around
ReplyThanks
BSreddy
A Running BMP in my Desktop.
Posted by Legacy on 10/18/2001 12:00amOriginally posted by: Jayachandran.C
How do i create a programme in Vc++ to create a Small Bitmap Sizing to the Thubnail Running Above my Task Bar. I got Some exe's from net That is a share ware. That A bird flying on my desktop or a Cat running above my taskbar that type i wan to make .
please help me to do this thanking you
ReplyHow: Internal OS implementation
Posted by Legacy on 06/26/2001 12:00amOriginally posted by: Alok Govil
How does the OS does it, ie, create non-rectangular windows.
ISSUE: When I hover the mouse on a window, the OS must determine on which window the mouse is currently on. So that the mouse-move message is put to the right window's queue. Same goes for all the messages, not excluding wm_paint.
For a rectangular window, this is easy. One needs say four comparisons to find out if the current mouse position is within a particular window.
How does the system do it for non-rectangular windows. For ellipitical windows, using the simple equation of an ellipse can do. But I have no idea if the OS does this.
For the regions created from bitmap, one way would be to check the bitmap again to see if the click was inside the window. But I have no idea if the OS does this.
Regards - Alok Govil
ReplyChanging the shape of a child window control (in non-mfc)
Posted by Legacy on 11/29/2000 12:00amOriginally posted by: Brian Rosenthal
I cannot figure out how to persistently change the clipping region of a child window control.
I have a rich edit control (non-mfc... created with CreateWindowEx), and I want to change the visible area of the control dynamically. There seem to be three approaches, and I cannot seem to figure out how to get any of them to work:
1. Call SetWindowRgn() on the child window control: this weirdly enough seems to make the specified region invisible, rather than visible, and is not persistent (the next InvalidateRect call re-draws the region.
2. Call SelectClipRgn(): this isn't persistent after the display context is released. The following code for example completely ignores my call to SelectClipRgn():
hdc = GetDC(hwnd);
rgn1 = CreateRectRgn(0, 0, 50, 50);
(void)SelectClipRgn(hdc, rgn1);
(void)ReleaseDC(hwnd, hdc);
hdc = GetDC(hwnd);
(void)GetClipBox(hdc, &WinRect);
rgn1 = CreateRectRgnIndirect((const RECT *)(&WinRect));
hbr = (HBRUSH) GetStockObject(WHITE_BRUSH);
(void)FillRgn(hdc, rgn1, hbr);
...
3. Intercept the WM_PAINT message of the control, and change the clipping region before the control is painted. The problem here is that I don't know how to intercept the child window WM_PAINT message without completely re-writing the control, and that doesn't seem to be the right solution.
Thank you,
Brian
Brian Rosenthal
ReplyChief Technology Officer
MyBestHealth, Inc.
brosenthal@mybesthealth.com
Changing a Window's Shape
Posted by Legacy on 05/26/2000 12:00amOriginally posted by: Nilesh Karkhanis
It works great!! and shows the window with the specified
region but if the window is dragged then the phantom lines
which are shown while dragging shows the default rectangular
region rather then the windows visible region.
Can u suggest some way to solve it..
Thanks
Nilesh Karkhanis
ReplyWorks Well!! I put it in Initdialog()
Posted by Legacy on 10/05/1999 12:00amOriginally posted by: Paul Bright
This works well and I put this in Initdialog() function and it changed the shape of that window.
ReplyRE : HOWTO: my Window's Shape from bitmap
Posted by Legacy on 07/04/1999 12:00amOriginally posted by: YongHoon Lee
Visit to
Reply/bitmap/bmp_to_rgn.shtml
You can find BitmapToRegion() function.
And visit to
/bitmap/index.shtml.
fixed bug.
What about cool stuff that WindowBlinds does?
Posted by Legacy on 06/16/1999 12:00amOriginally posted by: r. lake
Window Regions are nice, but isn't it only useful if you extend it so that the window is completely customized?
Reply
Changing a Window's Shape
Posted by Legacy on 05/02/1999 12:00amOriginally posted by: Rik
ReplyLoading, Please Wait ...