***************************************************************
*  Go to Dragon's VB Code Corner for more useful sourcecode:  *
*  http://personal.inet.fi/cool/dragon/vb/                    *
***************************************************************

The SetWindowRgn API function seems to be one of those anonymous 
functions, that nearly no-one seems to know about. Still it is a 
very useful function, because it allows you to change the shape of 
a window or control to almost any shape including round, elliptic, 
rectangular and any shape that can be defined as a polygon, or as 
a number of polygons.
I have made two functions (or rather subs), that simplify the use 
of this API.

The first function is makeEllipticWindow. This function is used to 
create elliptic windows, as you might expect :)

   Call it like this:
     makeEllipticWindow object.hWnd, 0, 0, 200, 200

The coordinates specify the corners of a box that the ellipse fits in. So, in the example 
the coordinates specify a box with corners on (0,0) and (200,200), and thus the resulting 
region is a circle with a diameter of 200 pixels.

The second function is makePolyWindow. This function is, of course, used to create windows 
consisting of polygon shapes.

   Call it like this:
   
   'First use point_array to specify the points for the polygon:
   ReDim point_array(0 to 2)

   point_array(0).x = 0
   point_array(0).y = 0
   point_array(1).x = 200
   point_array(1).y = 0
   point_array(2).x = 0
   point_array(2).y = 150

   'Now call the function:
   makePolyWindow object.hWnd

This would make the object triangular shaped, with a width of 200, and a height of 150.
Note that you don't have to make the polygon closed if you dont want to, because Win 95
(or NT) can handle that automatically, There is however nothing that stops you from 
making the polygon closed, by making the coordinates for the last point the same as for 
the first point, but, as I said, this is not necessary.

Paste the following code into a module:
'//*********************************//'

Type POINTAPI
    x As Long
    y As Long
End Type

Public point_array() As POINTAPI

Public Const ALTERNATE = 1

Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long


Public Sub makeEllipticWindow(hWnd As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
    
    Dim lRetVal As Long, lRgn As Long
        
    'Create an elliptic region
    lRgn = CreateEllipticRgn(X1, Y1, X2, Y2)
    
    'Make the window look like the region we created
    lRetVal = SetWindowRgn(hWnd, lRgn, True)

End Sub

Public Sub makePolyWindow(hWnd As Long)
    
    Dim lRetVal As Long, lRgn As Long
        
    'Create a polygon region from the points specified in
    'point_array()
    lRgn = CreatePolygonRgn(point_array(0), UBound(point_array) + 1, ALTERNATE)
    
    'Make the window look like the region we created
    lRetVal = SetWindowRgn(hWnd, lRgn, True)
    
End Sub
