Click here to Skip to main content
13,249,478 members (34,203 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 24 Dec 2004

Changing the Default form of Dialog Window

, 24 Dec 2004
Rate this:
Please Sign up or sign in to vote.
Changing the default form of dialog window making it as a circle instead of rectangular form.




If you compile your program the first time, you will see that the created window's shape (form) is rectangular(figure1.1). So if you want to change its default form to circular (See figure1.2) form or any other form do the following steps…

To do this, we will use SetWindowRgn() to set the window region.

Using the code

  1. Create or declare a variable of type (CRgn) & (CRect).
  2. Write this code in OnInitDialog() message handler function.
    CRect m_rect;
    CRgn m_rgn;

First, GetClientRect() copies the client coordinates of the CWnd client area into the only passed argument LPRECT. It copies the client area of the window into the only passed argument that is of type LPRECT. Then, we use CreateEllipticRgn() to create or specify an elliptical region in a bounding rectangle see figure(2). So you pass the four edges of the rectangle to this function.

Figure (2)

In this figure, we create the blue circular form and omit the red components of the general rectangular form.

  • Assume the whole window is the red rectangle shown above and the customized form (circular form) you want your dialog to be taken is the blue circle.
  • To specify the form or change the form of your dialog, call the CWnd member function SetWindowRgn().

SetWindowRgn() sets a window's region and it takes two arguments, first is a handle to the specified region using CreateEllipticRgn() function and the second argument specifies whether to redraw the window after setting the region. If you use “TRUE” as the second argument then OS redraws the window after specifying the region.

Snippet Code (for self study)

Change the contents of OnInitDialog() message handler function to the following and see the changes made to your dialog when compliling and running your application… it will be like the following figures:


    CRgn m_rgn1,m_rgn2,result;
    CRect rect
    //getting the dimensions of our dialog & 
    //saving the dimensions in rect member…
    GetClientRect( &rect);
    m_rgn1.CreateEllipticRgn(10,10,rect.Width()-150, rect.Height());
    m_rgn2.CreateEllipticRgn(rect.Width()/2 – 50 , 
           10 , rect.Width() , rect.Height());
    VERIFY(result.CreateRectRgn( 0, 0 , 200 , 200 ));
    Int nCombineResult= result.CombineRgn( &m_rgn1 , m_rgn2 , RGN_OR);
    ASSERT(nCombineResult !=ERROR || nCombineResult != NULLREGION);
    SetWindowRgn( result, TRUE);

Resulting dialog will be in the following form:

For the program linked with this article, it will be posted after at least one week …

Sorry because I am very busy in my exams…


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

Technical Lead Ministry of Higher Education
Egypt Egypt
My name is mohamed, & I'm from Egypt,in the faculty of computers.I began with visual c++ for two years ago.when I began with it I found it is very hard toundertand but when continue with it I find
it's very easy .
So,hopes to write to me...

You may also be interested in...


Comments and Discussions

GeneralError in SetWindowRgn usage Pin
Michael Dunn24-Dec-04 6:19
sitebuilderMichael Dunn24-Dec-04 6:19 
GeneralRe: Error in SetWindowRgn usage Pin
Star_Friend2-Aug-05 6:42
memberStar_Friend2-Aug-05 6:42 

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 | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 24 Dec 2004
Article Copyright 2004 by Star_Friend
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid