Changing a Window's Shape


In most newsgroups that have something to do with Windows programming there are postings on how to change window's shape. I thought that there must be an article about this here, and when I didn't find one, I decided to write one myself.

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.


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Cloud has the potential to offer many benefits that can enable great success within your business. However, there are still many myths floating around about backing up to the cloud. In this eBook, you'll discover the truth about five of the most common cloud myths, including myths about security, maintaining regulatory compliance and more. Get to the truth, so you can backup to the cloud with confidence.

  • Why use NoSQL? Innovative companies like AT&T, GE, and PayPal have successfully transitioned from relational to NoSQL for their critical web, mobile, and IoT applications. By understanding where to introduce NoSQL, how to model and access the data, and how to manage and monitor a distributed database, you can do the same. This white paper explains the need for non-relational databases, describes advantages of NoSQL, and clarifies the important difference between SQL and NoSQL databases. We walk you …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date