Ayo Sobat mari kita belajar lagi , dan pada kesempatan kali ini saya akan menjelaskan cara membuat SysTray yang sederhana di Visual basic.
Yang anda butuhkan pertama adalah 1 buah Module dan 1 buah Form, dan pada module itu anda masukkan kode berikut:
'Code
Option Explicit
Public Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeout As Long
szInfoTitle As String * 64
dwInfoFlags As Long
End Type
Public blnClick As Boolean
Public vbTray As NOTIFYICONDATA
Public Const SWP_NOMOVE As Long = &H2
Public Const SWP_NOSIZE As Long = &H1
Public Const Flags As Long = SWP_NOMOVE Or SWP_NOSIZE
Public Const WM_RBUTTONUP As Long = &H205
Public Const WM_RBUTTONCLK As Long = &H204
Public Const WM_LBUTTONCLK As Long = &H202
Public Const WM_LBUTTONDBLCLK As Long = &H203
Public Const WM_MOUSEMOVE As Long = &H200
Public Const NIM_ADD As Long = &H0
Public Const NIM_DELETE As Long = &H2
Public Const NIF_ICON As Long = &H2
Public Const NIF_MESSAGE As Long = &H1
Public Const NIM_MODIFY As Long = &H1
Public Const NIF_TIP As Long = &H4
Public Const NIF_INFO As Long = &H10
Public Const NIS_HIDDEN As Long = &H1
Public Const NIS_SHAREDICON As Long = &H2
Public Enum TypeBallon
NIIF_NONE = &H0
NIIF_WARNING = &H2
NIIF_ERROR = &H3
NIIF_INFO = &H1
NIIF_GUID = &H4
End Enum
Public Const HWND_NOTOPMOST As Long = -2
Public Const HWND_TOPMOST As Long = -1
Public Sub SystrayOn(Form As Form, IconTooltipText As String)
With vbTray
.cbSize = Len(vbTray)
.hWnd = frm.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.szTip = Trim(IconTooltipText$) & vbNullChar
.hIcon = frm.Icon
End With
Call Shell_NotifyIcon(NIM_ADD, vbTray)
App.TaskVisible = False
End Sub
Public Sub SystrayOff(Form As Form)
With vbTray
.cbSize = Len(vbTray)
.hWnd = frm.hWnd
.uID = vbNull
End With
Call Shell_NotifyIcon(NIM_DELETE, vbTray)
End Sub
Public Sub ChangeToolTip(Form As Form, IconTooltipText As String)
'Merubah tulisan di systray
With vbTray
.cbSize = Len(vbTray)
.hWnd = frm.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.szTip = Trim(IconTooltipText$) & vbNullChar
.hIcon = frm.Icon
End With
Call Shell_NotifyIcon(NIM_MODIFY, vbTray)
End Sub
Public Sub FormOnTop(frm As Form)
'Puts your form ontop of all the other windows!
Call SetWindowPos(frm.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, Flags)
End Sub
Public Sub MakeBalloon(frm As Form, Message As String, Title As String, Optional balType As TypeBallon = NIIF_INFO)
'Set a Balloon tip on Systray
'Call RemoveBalloon(frm), This removes any current Balloon Tip that is active.
'If you want Balloon Tips to "Stack up" and display in sequence
'after each times out (or you click on the Balloon Tip to clear it),
'comment out the Call below.
Call RemoveBalloon(frm)
With vbTray
.cbSize = Len(vbTray)
.hWnd = frm.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_INFO Or NIF_MESSAGE Or NIM_MODIFY 'Or NIF_TIP 'NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = frm.Icon
.dwState = 0
.dwStateMask = 0
.szInfo = Message & Chr(0)
.szInfoTitle = Title & Chr(0)
'Choose the message icon below, NIIF_NONE, NIIF_WARNING, NIIF_ERROR, NIIF_INFO
.dwInfoFlags = balType
End With
Call Shell_NotifyIcon(NIM_MODIFY, vbTray)
End Sub
Public Sub RemoveBalloon(frm As Form)
'Kill any current Balloon tip on screen for referenced form
With vbTray
.cbSize = Len(vbTray)
.hWnd = frm.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_INFO Or NIF_MESSAGE Or NIM_MODIFY
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = frm.Icon
.dwState = 0
.dwStateMask = 0
.szInfo = Chr(0)
.szInfoTitle = Chr(0)
.dwInfoFlags = NIIF_NONE
End With
Call Shell_NotifyIcon(NIM_MODIFY, vbTray)
End Sub
Kemudian kita ganti caption di formnya menjadi Frm , kemudian anda isikan kode berikut di dalam form itu.
'code
SystrayOn frm, "Welcome" 'Anda dapat menganti Welcome itu dengan kata2 anda sendiri
Udah jadi deh ,dan sekarang anda bisa menjalankanya dengan meng click F5.
Udah dulu yah nanti kalau saya kasih tahu lagi yang laenya...........sekian dan terima kasih. Dari: Rougerdeluffy
0 comments:
Post a Comment