![]() |
Desktop Development »
Dialogs and Windows »
Dialogs
Intermediate
Simple way to create non-rectangular shaped dialogsBy abhinabaThis article outlines a simple way to create dialogs which are not rectangular in shape |
VC6, Windows, Visual Studio, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
All the required code is in the OnInitDialog method of the dialog
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))); ...
Individual elliptic regions are then created using the coordinates of the dialog's window
// Get the rectangle CRect rect; GetWindowRect(&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);
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);
The dialogs shape is changed using the following code
// Set the window region SetWindowRgn(static_cast<HRGN>(rgn1.GetSafeHandle()), TRUE);
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
rgn1.Detach();
rgn2.Detach();
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Dec 2003 Editor: Nishant Sivakumar |
Copyright 2003 by abhinaba Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |