Pada artikel kali ini admin akan berbagi sebuah kode yang berfungsi untuk untuk menampilkan form sebagai notifikasi.
Notifikasi yang dimaksud adalah form yang kita buat ini berfungsi untuk memberitahukan kepada user dimana notifikasi ini muncul dikanan bawah monitor.
Notifikasi yang kita akan buat ini nantinya mirip dengan notifikasi anti virus.
Untuk hasil lebih jelasnya perhatikan gambar dibawah ini :
Notifikasi Transfarans |
Bagaimana cara membuat form notifikasi form seperti gambar diatas, berikut adalah langkah-langkahnya :
1. Buka Form VB6 Standar EXE
2. Pada Form tanamkan 2 Commandbutton dan 2 Timer (interval=100)
3. Desainlah Form seperti gambar dibawah ini :
Desain Form |
4. Kemudian ketik kode dibawah ini :
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 command1_Click()
'Kode selanjutnya disini ....
blnUp = False
Timer1.Enabled = True
End Sub
Private Sub command2_Click()
'kode selanjutnya disini ....
blnUp = False
Timer1.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
Timer2.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 timer2_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
Timer2.Enabled = False
MakeTransparan Me.hwnd, 100
End If
End Sub
Private Sub timer1_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))
Timer1.Enabled = False
Else
Top = Top - s
End If
Else
Top = Top + s
If Top >= v Then End
End If
End Sub
5. Kemudian jalankan project anda dan perhatikan form yang muncul secara perlahan dan transfarans disudut kanan bawah minitor.
Demikianlah artikel kali tentang Cara Membuat Form Notifikasi Dengan Efek Tranfarans Dengan Kode VB6.
Semoga artikel ini bermanfaat buat kita semua.amin.
Selamat mencoba semoga berhasil
No comments:
Post a Comment