Changing a Window's Shape | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 5, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.