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
- Create or declare a variable of type (
CRgn
) & (CRect
).
- 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
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�