dcsimg
December 7, 2016
Hot Topics:

Creating Odd Shaped Forms

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »

In order to create shaped Windows, you need to create some regions!

Create Rectangles

Public Declare Function CreateRectRgn _
   Lib "gdi32" _
   (ByVal X1 As Long, ByVal Y1 As Long, _
   ByVal X2 As _
   Long, ByVal Y2 As Long) As Long

This syntax creates a rectangular region with the upper left corner defined by X1, Y1 and the lower right corner defined by X2, Y2.

Create Ellipses

Public Declare Function CreateEllipticRgn _
   Lib "gdi32" _
   (ByVal X1 As Long, ByVal _
   Y1 As Long, ByVal X2 As Long, _
   ByVal Y2 As Long) As Long

This syntax creates an elliptic region that fits within the bounds specified by X1, Y1 and X2, Y2.

Create Rounded Rectangles

Public Declare Function CreateRoundRectRgn _
   Lib "gdi32" _
   (ByVal X1 As Long, ByVal Y1 As Long, _
   ByVal X2 As Long, _
   ByVal Y2 As Long, ByVal X3 As Long, _
   ByVal Y3 As Long) As Long

This creates a rectangular region, like the CreateRectRgn. However, it allows you to round the corners, using the X3 and Y3 parameters. If set to 0, they produce square corners. If set at the width/height, they produce completely rounded corners.

Creating any Shape you Like

Public Declare Function CreatePolygonRgn _
   Lib "gdi32" _
   (lpPoint As POINTAPI, _
   ByVal nCount As Long, ByVal _
   nPolyFillMode As Long) As Long

This is function allows you to create any shaped region. The shape of it is limited only by your patience to plug in numbers. To use this function, create an array of POINTAPI structures. In the lpPoint parameter pass the first element in the array, and in the nCount parameter, pass the number of points. The nPolyFillMode parameter determines how the filled area of the region is selected. There are only subtle differences between the two options (WINDING and ALTERNATE), but if you fiddle round, you may spot the difference.
Windows automatically joins the first and last points to make a closed figure.

Creating Several Custom Shapes

Public Declare Function CreatePolyPolygonRgn _
   Lib "gdi32" _
   (lpPoint As POINTAPI, lpPolyCounts _
   As Long, ByVal nCount As _
   Long, ByVal nPolyFillMode As Long) As Long

As the name suggests, this function creates a region of several shapes. As before, the lpPoint is the first element in an array of POINTAPIs, and nCount is the number of elements. However, lpPolyCounts is the first element in an array of Longs. Each element in this array defines how many points each polygon has. Therefore, the sum of all of the elements of lpPolyCounts must equal nCount.
A similar effect can be achieved using several individual polygons, combined into one region.





Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel