Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How all of those cool apps having a window with a shape that are not Bill Gates' borring rectangles?

Window Designing

How all of those cool apps having a window with a shape that are not Bill Gates' borring rectangles?

by  dcgsmix  Posted    (Edited  )
They use what called regions, the following information is from MSDN, and email me if you need more help...

To set a window's region use:
SetWindowRgn(hwnd, hrgn, TRUE);
when the hwnd is the handle to your window
the hrgn is a handle to a region, or NULL if you want to remove the region
the 3rd parameter tells windows to redraw your window or not. TRUE is redraw, FALSE is dont redraw, use it if your window si still not visibled.

To create a region:

Rectangle region:

HRGN CreateRectRgn(
int nLeftRect, // x-coordinate of region's upper-left corner
int nTopRect, // y-coordinate of region's upper-left corner
int nRightRect, // x-coordinate of region's lower-right corner
int nBottomRect // y-coordinate of region's lower-right corner
);
or:

HRGN CreateRectRgnIndirect(
CONST RECT *lprc // pointer to the rectangle
);

Round region:

HRGN CreateRoundRectRgn(
int nLeftRect, // x-coordinate of the region's upper-left corner
int nTopRect, // y-coordinate of the region's upper-left corner
int nRightRect, // x-coordinate of the region's lower-right corner
int nBottomRect, // y-coordinate of the region's lower-right corner
int nWidthEllipse, // height of ellipse for rounded corners
int nHeightEllipse // width of ellipse for rounded corners
);

Elliptic region:

HRGN CreateEllipticRgn(
int nLeftRect, // x-coord of the upper-left corner of the bounding rectangle
int nTopRect, // y-coord of the upper-left corner of the bounding rectangle
int nRightRect, // x-coord of the lower-right corner of the bounding rectangle
int nBottomRect // y-coord of the lower-right corner of the bounding rectangle
);
or:

HRGN CreateEllipticRgnIndirect(
CONST RECT *lprc // pointer to bounding rectangle
);

Polygon region (the most cool but complicated one):

HRGN CreatePolygonRgn(
CONST POINT *lppt, // pointer to array of points
int cPoints, // number of points in array
int fnPolyFillMode // polygon-filling mode
);

fnPolyFillMode:
Specifies the fill mode used to determine which pixels are in the region. This parameter can be one of the following values: Value Meaning
ALTERNATE Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
WINDING Selects winding mode (fills any region with a nonzero winding value).


For more information about these modes, see the SetPolyFillMode function.



All that information you can find in the MSDN
There a lot of functions you can use for converting regions to rect, inverting them, painting them, comparing rects sizes with polygon region, and even creating poly-polygon regions.


To delete a region (clean the memory!!!):
use DeleteObject

To set a region to HDC (device context) and not a HWND (window's handle):
use SelectObject



Hope that helps,
Daniel Cohen Gindi
dcgsmix@gmx.net
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top