Langkah- Langkah Contoh
Tambahkan kode hijau berikut untuk deklarasi bagian modul standar dalam proyek Anda :
' tipe yang ditetapkan pengguna yang dibutuhkan oleh panggilan API Shell_NotifyIcon
Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type
'constants required by Shell_NotifyIcon API call:
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA
Tambahkan kode merah berikut untuk bentuk apapun dalam form Anda bahwa Anda ingin menanggapi System Tray Icon , atau Ikon Pemberitahuan , untuk aplikasi Anda :
Private Sub Form_Load ( )
' format harus benar-benar terlihat sebelum memanggil Shell_NotifyIcon
Me.Show
Me.Refresh
With nid
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = "Your ToolTip" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'this procedure receives the callbacks from the System Tray icon.
Dim Result As Long
Dim msg As Long
'the value of X will vary depending upon the scalemode setting
If Me.ScaleMode = vbPixels Then
msg = X
Else
msg = X / Screen.TwipsPerPixelX
End If
Select Case msg
Case WM_LBUTTONUP '514 restore form window
Me.WindowState = vbNormal
Result = SetForegroundWindow(Me.hwnd)
Me.Show
Case WM_LBUTTONDBLCLK '515 restore form window
Me.WindowState = vbNormal
Result = SetForegroundWindow(Me.hwnd)
Me.Show
Case WM_RBUTTONUP '517 display popup menu
Result = SetForegroundWindow(Me.hwnd)
Me.PopupMenu Me.mPopupSys
End Select
End Sub
Private Sub Form_Resize()
'this is necessary to assure that the minimized window is hidden
If Me.WindowState = vbMinimized Then Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'this removes the icon from the system tray
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub mPopExit_Click()
'called when user clicks the popup menu Exit command
Unload Me
End Sub
Private Sub mPopRestore_Click()
'called when the user clicks the popup menu Restore command
Dim Result As Long
Me.WindowState = vbNormal
Result = SetForegroundWindow(Me.hwnd)
Me.Show
End Sub
Membuat Pengaturan Properti berikut pada bentuk yang sama yang Anda menambahkan kode di atas :
Property Required Setting for Taskbar Notification Area example ----------------------------------------------------------------------- Icon = The icon you want to appear in the system tray. Minbutton = True ShownInTaskbar = False
Menambahkan item menu berikut untuk bentuk yang sama dengan menggunakan Menu Editor :
Caption Name Enabled Visible Position --------------------------------------------------------- &SysTray mPopupSys True False Main Level &Restore mPopRestore True True Inset one &Exit mPopExit True True Inset one
Anda dapat menambahkan item menu tambahan yang diperlukan .Taskbar Notification Area FleksibilitasAnda dapat memodifikasi ToolTip yang muncul di atas ikon Pemberitahuan dengan mengubah baris berikut dalam prosedur Form_Load :
. szTip = " ToolTip Anda " & vbNullChar
Ganti " ToolTip Anda " dengan teks yang ingin Anda tampilkan .
Anda dapat memodifikasi Icon yang muncul di Notification Area Taskbar dengan mengubah baris berikut dalam prosedur Form_Load :
. hIcon = Me.Icon
Ganti Me.Icon dengan Icon dalam proyek Anda .
Anda dapat mengubah pengaturan Notification Area Taskbar setiap saat setelah penggunaan konstan NIM_ADD dengan pemindahan nilai-nilai dalam variabel nid dan kemudian menggunakan variasi berikut dari API panggilan Shell_NotifyIcon :
Shell_NotifyIcon NIM_MODIFY , nid .
Namun, jika Anda ingin bentuk yang berbeda untuk menerima callback , maka Anda akan perlu menghapus ikon saat pertama menggunakan " Shell_NotifyIcon NIM_Delete , nid " sebagai fungsi NIM_Modify tidak akan menerima HWND baru , atau Anda akan perlu untuk menambahkan Icon lain untuk yang systray untuk bentuk baru menggunakan " Shell_NotifyIcon NIM_ADD , nid " setelah mengisi jenis nid dengan bentuk-bentuk baru hWND . Anda juga dapat mendeklarasikan salinan yang terpisah dari jenis nid untuk setiap bentuk yang Anda ingin menampilkan ikon dalam Windows System Tray dan mengubah mereka dalam acara mengaktifkan masing-masing form menggunakan NIM_DELETE dan NIM_ADD urutan .
Thank's for reading the articelCara membuat system try di visual basic 6.0 / VB6 .If You want to copy paste your website please tag my link Cara membuat system try di visual basic 6.0 / VB6 Intro My Website.
0 comments:
Post a Comment