Friday, June 8, 2012

Notify Form Dengan Effect Transparent Hover

Menjelaskan mengenai cara membuat notify form yang menggunakan effect transparent hover - Apa yang dimaksud dengan notify form itu? notify form adalah form yang bertugas memberitahukan sesuatu kepada user, umumnya notify form muncul sebelah kanan bagian bawah. Beberapa software yang menggunakan notify form diantaranya: Mozilla Firefox, Orbit Downloader, IDM, Avira, software-software Anti Virus, dan banyak lagi. Untuk membuat notify form, khususnya yang memiliki effect transparent hover (terinspirasi dari software notepad++ pada dialog findnya), copy dan pastekan kode di bawah ini:
'---------------------------------------------------------------------------------------------------------- 
'http://khoiriyyah.blogspot.com
'coder: Administrator
'----------------------------------------------------------------------------------------------------------
Option Explicit

Dim
blnHighlighted As Boolean
Dim
blnMouseDownClick As Boolean 'bug fixed on flickering

Private Type
POINTAPI
X As Long
Y As Long
End Type

Private Declare Function
ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function
GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function
GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Sub
InitCommonControls Lib "COMCTL32.DLL" ()

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

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

Dim
iTransparant As Integer
Dim
blnUp As Boolean

Private Sub
Form_Initialize()
InitCommonControls
End Sub

Private Sub
MakeTransparan(hWndBro As Long, iTransp As Integer)
On Error Resume Next

Dim
ret As Long
ret = GetWindowLong(hWndBro, GWL_EXSTYLE)

SetWindowLong hWndBro, GWL_EXSTYLE, ret Or WS_EX_LAYERED
SetLayeredWindowAttributes hWndBro, RGB(255, 255, 0), iTransp, LWA_ALPHA
Exit Sub

End Sub

Private Sub
cmdOK_Click()
'Kode selanjutnya disini ....
blnUp = False
tmrNotify.Enabled = True
End Sub

Private Sub
cmdCancel_Click()
'kode selanjutnya disini ....
blnUp = False
tmrNotify.Enabled = True
End Sub

Private Sub
Form_Load()
MakeTransparan Me.hwnd, 100
Top = ((GetSystemMetrics(17) + GetSystemMetrics(4)) * Screen.TwipsPerPixelY)
Left = (GetSystemMetrics(16) * Screen.TwipsPerPixelX) - Width
blnUp = True
End Sub

Private Sub
Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnMouseDownClick = True
End Sub

Private Sub
Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnHighlighted Then Exit Sub
blnHighlighted = True
tmrSemiTransparent.Enabled = True
MakeTransparan Me.hwnd, 255
End Sub

Private Sub
Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnMouseDownClick = False
End Sub

Private Sub
tmrSemiTransparent_Timer()
If blnMouseDownClick Then Exit Sub
Dim pt As
POINTAPI
GetCursorPos pt
ScreenToClient hwnd, pt
If
(pt.X < 0 Or pt.Y < 0) Or _
(pt.X > (Me.ScaleLeft + Me.ScaleWidth) / Screen.TwipsPerPixelX) Or _
(pt.Y > (Me.ScaleTop + Me.ScaleHeight) / Screen.TwipsPerPixelY) Then
blnHighlighted = False
tmrSemiTransparent.Enabled = False
MakeTransparan Me.hwnd, 100
End If
End Sub

Private Sub
tmrNotify_Timer()
Const s = 100
Dim v As Single
v =
(GetSystemMetrics(17) + GetSystemMetrics(4)) * Screen.TwipsPerPixelY
If blnUp = True Then
If
Top - s <= v - Height Then
Top = Top - (Top - (v - Height))
tmrNotify.Enabled = False
Else
Top = Top - s
End If
Else
Top = Top + s
If
Top >= v Then End
End If
End Sub