MorphostLab

Tempat nongkrongnya Morphic dan kawan-kawan

Alphablend

Posted by Morphic pada September 22, 2009


Rencananya artikel ini kuberi judul “Alphablend untuk antivirus” tapi kayaknya lebih cocok juga untuk semua software, gak Cuma antivirus.

Ada yang blum tahu alphablend?
Sederhananya alphablend itu animasi dari transparan ke padat dan kembali lagi ke transparan hingga menghilang….
Heh he hee… mungkin ada yang gak ngerti dengan definisinya ini…

Pernah lihat splashscreen morphost? Nah splashscreen Morphost memanfaatkan animasi alphablend.

Jadi untuk latihannya dibutuhkan:
1 form (visible = False)
2 timer (masing-masing interval = 50. masing-masing enable = False)

Source-nya kira-kira begini:
Option Explicit

Const LWA_BOTH = 3
Const LWA_ALPHA = 2
Const LWA_COLORKEY = 1
Const GWL_EXSTYLE = -20
Const WS_EX_LAYERED = &H80000

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 Declare Function SetLayeredWindowAttributes Lib “user32” _
(Byval hWnd As Long, Byval color As Long, Byval x As Byte, _
Byval alpha As Long) As Boolean
Dim TransNilai As Integer

Sub SetTrans(hWndTrans As Long, TransGet As Integer)
On Error Resume Next

Dim HitungTrans As Long
Hitungtrans = GetWindowLong(hwndTrans, GWL_EXSTYLE)

SetWindowLong hWndTrans, GWL_EXSTYLE, HitungTrans Or WS_EX_LAYERED
SetLayeredWindowAttributes hWndTrans, RGB(255, 255, 0), TransGet, LWA_ALPHA
Exit Sub

End Sub

Private Sub Form_Load()
Timer1.Enabled = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
transnilai = transnilai + 5
If transnilai > 255 Then transnilai = 255: Timer1.Enabled = False
settrans Me.hWnd, transnilai
Me.Show
End Sub

Private Sub Timer2_Timer()
On Error Resume Next
transnilai = transnilai – 5
If transnilai < 0 Then transnilai = 0: Timer2.Enabled = False: End
settrans Me.hWnd, transnilai
End Sub

Aku rasa kalo code tadi dah dicoba, pasti smuanya udah ngerti…

Sekian tutorial singkat ini..
Sekarang udah gak sempat lagi nulis tutorial cuy. Dah banyak tugas di kampus…

By:Morphic
Thanks to:
-mahasiswa FK USU 2009
-Haxeru
-Poet
-dll

Satu Tanggapan to “Alphablend”

  1. kevin said

    Thanks ya Sob

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: