Tuesday, October 20, 2009

Make Transparent Form in Visual Basic 6.0

Copy this code to module code

Public Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, _
ByVal x2 As Long, ByVal y2 As Long) As Long

Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long

Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal _
hRedraw As Boolean) As Long

Public Const RGN_DIFF = 4
Public Const RGN_OR = 2

Copy this code to form code

Private Sub Form_Load()
Dim Bingkai As Boolean

Bingkai = True
Me.ScaleMode = 3
Transparan Bingkai

End Sub

Private Sub Transparan(x As Boolean)
Dim a, b, c, d As Single
Dim p, q, r As Long
y = CreateRectRgn(0, 0, 0, 0)
a = ScaleX(Width, 1, 3)
b = ScaleY(Height, 1, 3)
c = (a - ScaleWidth) / 2
d = b - c - ScaleHeight
If x Then
p = CreateRectRgn(0, 0, a, b)
q = CreateRectRgn(c, d, a - c, b - c)
CombineRgn y, p, q, RGN_DIFF
End If
For i = 0 To Me.Controls.Count - 1
m = ScaleX(Me.Controls(i).Left, Me.ScaleMode, 3) + c
n = ScaleX(Me.Controls(i).Top, Me.ScaleMode, 3) + d
r = CreateRectRgn(m, n, _
ScaleX(Me.Controls(i).Width, Me.ScaleMode, 3) + m, _
ScaleY(Me.Controls(i).Height, Me.ScaleMode, 3) + n)
CombineRgn y, r, y, RGN_OR
Next
SetWindowRgn hwnd, y, True

End Sub

No comments:

Post a Comment