Click here to Skip to main content
13,800,377 members
Click here to Skip to main content
Add your own
alternative version


90 bookmarked
Posted 6 Dec 2003

Simple way to create non-rectangular shaped dialogs

, 6 Dec 2003
Rate this:
Please Sign up or sign in to vote.
This article outlines a simple way to create dialogs which are not rectangular in shape


Normally Dialog Boxes are rectangular in shape. Various methods can be adopted to make them non-rectangular in shape. However, most of these methods are complicated and suited for application that uses skinning to create dialogs with the shape of a skin or image. If the required shape of the dialog is simple like a rectangle with rounded corners or an ellipse, then a much simpler method can be used. In this method multiple CRgn objects are created and then combined (union of regions) to create a compound region. The dialog is then given the shape of the compound region.

The Code

All the required code is in the OnInitDialog method of the dialog

Step 1: Set Dialog style

To change the shape of the dialog, in the OnInitDialog of the dialog the Caption and the Border of the dialog is removed.

//  Remove caption and border
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE)
     & (~(WS_CAPTION | WS_BORDER)));

Step 2: Create individual regions

Individual elliptic regions are then created using the coordinates of the dialog's window

//  Get the rectangle
CRect rect;
int w = rect.Width();
int h = rect.Height();

CRgn rgn1;
CRgn rgn2;

//  Create the top ellipse
rgn1.CreateEllipticRgn(1, 1, w, h/2 + 30);

//  Create the bottom ellipse
rgn2.CreateEllipticRgn(1, h/2 - 30, w, h);

Step 3: Combine the regions into one

The regions are combined to create a single region. The combination is actually a UNION of all the individual regions

//  Combine the two ellipses
CombineRgn(rgn1, rgn1, rgn2, RGN_OR);

Step 4: Change the shape of the dialog to the region

The dialogs shape is changed using the following code

//  Set the window region
SetWindowRgn(static_cast<HRGN>(rgn1.GetSafeHandle()), TRUE);

Step 5: Cleaning up

The CRgn object needs to be detached from the region, or else the CRgn destructor closes the HRGN handle when rgn objects go out of scope



  • Initial version


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I just love coding. I started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VB, VC++ and now C#/.NET.

I received a Bachelor of Technology degree in Computer Science from University of Calcutta in 2001.

I worked for some time in Texas Instruments, Adobe Systems and now in Microsoft India Development Center in the Visual Studio Team Systems.

I am from the City of Joy, Kolkata in India, but now live and code Hyderabad.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Bhavin Jagad23-Jul-10 0:24
memberBhavin Jagad23-Jul-10 0:24 
GeneralCreate a Non Rectangle shaped Dialog Pin
Dabara29-Jul-08 5:51
memberDabara29-Jul-08 5:51 
GeneralSimple but helpful. Pin
Zhou'Liang10-Apr-08 17:23
memberZhou'Liang10-Apr-08 17:23 
GeneralExcellent sample code Pin
TigerTom21-Feb-08 1:44
memberTigerTom21-Feb-08 1:44 
QuestionGood work, how about border? Pin
Super Hornet5-Dec-06 17:55
memberSuper Hornet5-Dec-06 17:55 
QuestionHow to create non-rectangular shaped Buttons Pin
<bold>PravinSingh19-May-06 3:11
member<bold>PravinSingh19-May-06 3:11 
AnswerRe: How to create non-rectangular shaped Buttons Pin
abhinaba19-May-06 11:58
memberabhinaba19-May-06 11:58 
QuestionHow to create complex shape windows? Pin
Tanmay Sathe10-Mar-04 8:53
memberTanmay Sathe10-Mar-04 8:53 
AnswerRe: How to create complex shape windows? Pin
abhinaba12-Mar-04 3:27
memberabhinaba12-Mar-04 3:27 
GeneralSomething so cool... Pin
Andrew Lawrence2-Mar-04 10:16
memberAndrew Lawrence2-Mar-04 10:16 
Generalvery good Pin
ali khalilvand17-Dec-03 0:15
memberali khalilvand17-Dec-03 0:15 
GeneralVery Useful Pin
bkimble15-Dec-03 14:34
memberbkimble15-Dec-03 14:34 
GeneralThanks for the support Pin
abhinaba11-Dec-03 19:41
memberabhinaba11-Dec-03 19:41 
GeneralWhat's new here? Useless article Pin
Pete Goodsall11-Dec-03 3:56
memberPete Goodsall11-Dec-03 3:56 
GeneralRe: What's new here? Useless article Pin
kriaz28-Jul-04 0:29
memberkriaz28-Jul-04 0:29 
GeneralRe: What's new here? Useless article Pin
Pete Goodsall28-Jul-04 1:59
memberPete Goodsall28-Jul-04 1:59 
GeneralRe: What's new here? Useless article Pin
gmohanraj11-Feb-10 3:01
membergmohanraj11-Feb-10 3:01 
General[Message Deleted] Pin
Anonymous9-Dec-03 7:39
memberAnonymous9-Dec-03 7:39 
GeneralRe: What's new here? Useless article. Pin
tidhar9-Dec-03 22:02
membertidhar9-Dec-03 22:02 
GeneralRe: What's new here? Useless article. Pin
abhinaba9-Dec-03 22:06
memberabhinaba9-Dec-03 22:06 
GeneralRe: What's new here? Useless article. Pin
Trollslayer5-Nov-06 7:55
mentorTrollslayer5-Nov-06 7:55 
GeneralRe: What's new here? Useless article. PinPopular
  Forogar  15-Dec-03 3:20
professional  Forogar  15-Dec-03 3:20 
GeneralRe: What's new here? Useless article. Pin
binyo6630-Jun-09 2:07
memberbinyo6630-Jun-09 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181214.1 | Last Updated 7 Dec 2003
Article Copyright 2003 by abhinaba
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid