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!

help! SetWindowRgn (no MFC) --- Very Simply

Status
Not open for further replies.

lGOOODl

Programmer
Dec 4, 2001
31
DK
Hi,

I have a liltle problem whit the SetWindowRgn. i can get it to work corectly. So i was hoping taht some of you could give an example, on how it works ?

Thanks
..:::GOOOD:::..
 
Hey,

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
 
Thank, this is great. This could sound like I'm a litle stupid, but i have searched the MSDN libary, but i didnt find any useful things! But this covers all my problems! ones again Thanks.

..:::GOOOD:::..
 
Its ok

I dont know why, but everybody here find nothing in the MSDN, so i'm the MSDN seeker in this game...

Bye,
Daniel Cohen Gindi
dcgsmix@gmx.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top