INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...Keep up the good work - excellent site - i'd been looking for something like this for ages !..."

Geography

Where in the world do Tek-Tips members come from?

Microsoft: Visual C++ FAQ

Window Designing

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

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

Back to Microsoft: Visual C++ FAQ Index
Back to Microsoft: Visual C++ Forum
My FAQ Archive
Email This FAQ To A Friend

My Archive