Minggu, 09 Agustus 2009

Efek Transparasi Form dan Taskbar pada VB6

Disini kita coba untuk berlatih membuat objek transparasi pada Form dan Taskbar windows dengan menggunakan Visual Basic 6. Sebelumnya rancanglah sebuah Form dengan komponennya seperti gambar dibawah ini:


kemudian gunakan dan deklarasikan API Functions seperti dibawah ini didalam Form1:
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" _
(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Declare Function GetWindowLong Lib "user32.dll" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal Ipclassname As String, ByVal Ipwindowname As String) As Long

Private taskbarhwnd, starthwnd, startshwnd As Long
Dim result
Dim x As Integer
Dim t As Boolean

Buatlah 2 (dua) buah prosedur dengan kode program sebagai berikut:
Private Sub SetLayeredWindow(ByVal hwnd As Long, ByVal bIsLayered As Boolean)
Dim WinInfo As Long
WinInfo = GetWindowLong(hwnd, -20)
If bIsLayered = True Then
WinInfo = WinInfo Or 524288
Else
WinInfo = WinInfo And Not 524288
End If
SetWindowLong hwnd, -20, WinInfo
End Sub

Private Sub SetTransparan(ByVal hwnd As Long, ByVal opacity As Byte, ByVal IsTransparent As Boolean)
If IsTransparent = True Then
SetLayeredWindow hwnd, True
SetLayeredWindowAttributes hwnd, 0, opacity, 2
ElseIf IsTransparent = False Then
SetLayeredWindow hwnd, False
End If
End Sub

Berikan event click pada kedua CheckBox dan tuliskan program sebagai berikut :
Private Sub Check1_Click()
If Check1.Value = 0 Then
HScroll1.Enabled = False
Text1.Enabled = False
Else
HScroll1.Enabled = True
Text1.Enabled = True
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 0 Then
HScroll2.Enabled = False
Text2.Enabled = False
Else
HScroll2.Enabled = True
Text2.Enabled = True
End If
End Sub

Berikan perintah pada Timer, Form dan Hscroll
Private Sub Form_Load()
HScroll1.Value = 250
HScroll2.Value = 250
End Sub

Private Sub Form_Unload(Cancel As Integer)
taskbarhwnd = FindWindow("shell_traywnd", "")
SetTransparan taskbarhwnd, 0, False
End Sub

Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub

Private Sub HScroll2_Change()
Text2.Text = HScroll2.Value
End Sub

Private Sub Timer1_Timer()
taskbarhwnd = FindWindow("shell_traywnd", "")
SetTransparan taskbarhwnd, HScroll1.Value, True
SetTransparan Me.hwnd, HScroll2.Value, True
End Sub

kemudian jalankan program, dan gerakkan masing-masing Horisontal Scroll untuk melihat hasil transparasi!
Selamat mencoba ....

0 komentar:

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Free Samples By Mail