![]() |
Source Code |
![]() |
![]() |
3 | Code Libraries |   |
  |
A window that's star-shaped, circular or tank-shaped |
|
Create windows of any geometric shape using SetWindowRgn - works with UserControls too! |
Just for fun, its surprisingly easy now to create Windows or controls of any shape whatsoever under Visual Basic.
The trick is to use the SetWindowRgn function. This function (supported under Windows 95 and NT 3.5+) allows you to set the clipping region for a window including the border. The shape of your region depends upon how you created it. You can create elliptical, polygonal, rectangular, and round regions via calls to the CreateEllipticalRgn, CreatePolygonRgn, CreateRectRgn, and CreateRoundRgn functions. You pass to the creation function the coordinates bounding the region that you wish to set, and the function returns a handle to the region. Once you have the handle to the region, you can pass it to SetWindowRgn,
whereupon the window assumes the shape. The declares you require to get started are (NB all declarations must be on one line or separated with underscores): ' ===============================================================' API declares for creating regions and setting a window's region ' =============================================================== ' Point Type POINTAPI     X As Long     Y As Long End Type ' Change region of a window: Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long ' Precanned region creation functions: Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long 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 ' Polygon region creation functions: Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long Declare Function CreatePolyPolygonRgn Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long ' Polygon type: Public Const WINDING = 2 ' Region combination: Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long     ' Region combination types:     Public Const RGN_AND = 1     Public Const RGN_COPY = 5     Public Const RGN_DIFF = 4     Public Const RGN_MAX = RGN_COPY     Public Const RGN_MIN = RGN_AND     Public Const RGN_OR = 2     Public Const RGN_XOR = 3     ' Region combination return values:     Public Const COMPLEXREGION = 3     Public Const SIMPLEREGION = 2     Public Const NULLREGION = 1 ' GDI Clear up: Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long And here is the code which will make a VB form or control elliptical:
And that's it. Have fun filling in the backgrounds, and try out the source code, which demonstrates a number of other techniques, including:
|
  |
![]() |
|
About Contribute Send Feedback Privacy
|