Postingan kali ini saya akan berbagi ilmu, bagai mana cara membuat sebuah form terlihat transparan saat dijalankan.
- Buka aplikasi Visual basic 6.0 dan buka sebuah project baru dan sebuah form
- tambah sebuah module dengan cara plilih menu bar Project danpilih Add Module lalu pilih Open.
- setelah terbuka module yang kita buat tadi masukan listing dibawah ini kedalam module :
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
Private Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Declare Function UpdateLayeredWindow Lib "user32" _
(ByVal hwnd As Long, ByVal hDCDst As Long, pptDst As Any, _
psize As Any, ByVal hDCSrc As Long, pptSrc As Any, crKey As Long, _
ByVal pblend As Long, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000
Public Function MakeTransparent(ByVal hwnd As Long, Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next
If Perc <> 255 Then
MakeTransparent = 1
Else
Msg = GetWindowLong(hwnd, GWL_EXSTYLE)
Msg = Msg Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hwnd, 0, Perc, LWA_ALPHA
MakeTransparent = 0
End If
If Err Then
MakeTransparent = 2
End If
End Function - stelah dimasukan ke module, kembali ke form dan tmbahkan 2 buah timer dan satu buah common button dengan caption "Keluar".
- masukan listing dibawah ini di timer1 : Private Sub Timer1_Timer()
If JmlPersen < jmlpersen =" JmlPersen" jmlpersen =" 230" interval =" 0"> - kemudian masukan listing ini di timer 2 : Private Sub Timer2_Timer()
If JmlPersen > 0 Then
JmlPersen = JmlPersen - 10
Else
Unload Me
Exit Sub
End If
MakeTransparent Me.hwnd, JmlPersen
End Sub - Masukan Listing ini di form load : MakeTransparent Me.hwnd, 0
JmlPersen = 0
Me.Timer1.Interval = 50 - Dan masukan listing ini di command button1 di event click:
Me.Timer1.Interval = 0
Me.Timer2.Interval = 50 - dan masukanlisting ini di General-Declaration :
Dim JmlPersen As Integer - dan jalan kan programnya
semoga bermanfaat.... AMIN
2 komentar:
God job...
Teruskan Sob...
Tanks Broooo