Click here to Skip to main content
Click here to Skip to main content

Changing the Default form of Dialog Window

By , 24 Dec 2004
Rate this:
Please Sign up or sign in to vote.

Figure(1.1)

Figure(1.2)

Introduction

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.
CMyDialog::OnInitDialog()
{
    CRect m_rect;
    CRgn m_rgn;
    GetClientRect(&m_rect);
    m_rect.NormalizeRect();
    m_rgn.CreateEllipticRgn(10,10,m_rect.Width(),m_rect.Height()+10);
    SetWindowRgn(m_rgn,TRUE);
}
/////

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:

CMyDialog::OnInitDalog()

CMyDialog::OnInitDialog()
{
    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…

License

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

Star_Friend
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...
Follow on   Google+

Comments and Discussions

 
GeneralError in SetWindowRgn usage PinsitebuilderMichael Dunn24-Dec-04 5:19 
GeneralRe: Error in SetWindowRgn usage PinmemberStar_Friend2-Aug-05 5:42 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 24 Dec 2004
Article Copyright 2004 by Star_Friend
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid