Library code snippets
Create a custom shaped form
Occasionally, you will notice a non-standard form that is round, or is not a simple rectangle. You can do this in VB by specifying the area of a form you want displayed, enabling you to create a round form, or a form with a hole in the middle... basically whatever you want.
To do this, you create 'regions' using CreateRectRgn, CreatePolygonRgn etc... then you add them to a variable using CombineRgn. Next, you tell windows to apply this region to your form using SetWindowRgn, thus creating your custom shaped form. Take a look at the code below, and try it out yourself!
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject
As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long,
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As
Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As
Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Const RGN_OR = 2
Private Sub pCreateSkin()
Dim lReturn As Long
Dim lRgnTmp As Long
Dim lSkinRgn As Long
Dim lWidth As Long
Dim lHeight As Long
lWidth = (ScaleWidth) / Screen.TwipsPerPixelX
lHeight = (ScaleHeight) / Screen.TwipsPerPixelY
lSkinRgn = CreateRectRgn(0, 0, 10, lHeight)
lRgnTmp = CreateRectRgn(0, 0, lWidth, 25)
lReturn = CombineRgn(lSkinRgn, lSkinRgn, lRgnTmp, RGN_OR)
lRgnTmp = CreateRectRgn(lWidth, 0, lWidth - 10, lHeight)
lReturn = CombineRgn(lSkinRgn, lSkinRgn, lRgnTmp, RGN_OR)
lRgnTmp = CreateRectRgn(0, lHeight, lWidth - 10, lHeight
- 10)
lReturn = CombineRgn(lSkinRgn, lSkinRgn, lRgnTmp, RGN_OR)
Call DeleteObject(lRgnTmp)
Call SetWindowRgn(hwnd, lSkinRgn, True)
End Sub
Related articles
Related discussion
-
how do you hide all in VB6
by CapnJack (1 replies)
-
Problem with Input File
by novavb6 (3 replies)
-
How to produce a txt file with a table??
by novavb6 (1 replies)
-
VB6 compatability from XP to Vista
by bronx (1 replies)
-
Fully justify code
by fresh (0 replies)
This thread is for discussions of Create a custom shaped form.