|
|
|
|
|
Dicas
|
|
Visual Basic (ActiveX/Controles/DLL)
|
|
|
Título da Dica: Colocando ícone no Tray
|
|
|
|
Postada em 13/3/2004 por Josefh Hennyere
'Num form insira 2 pictures box e insira dois "ÍCONES" diferentes a prioridade Picture 'Tem que ser ícone
'No form cole o código abaixo
Option Explicit Private 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 Private Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const WM_MOUSEMOVE = &H200 Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDBLCLK = &H206 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Dim nid As NOTIFYICONDATA
Private Sub CreateTrayIcon() nid.cbSize = Len(nid) nid.hwnd = Me.hwnd nid.uId = vbNull nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE nid.uCallBackMessage = WM_MOUSEMOVE nid.hIcon = Me.Icon If Trim(Me.Tag) <> "" Then If Right(Me.Tag, 1) <> Chr(0) Then nid.szTip = Trim(Me.Tag) & Chr(0) Else nid.szTip = Trim(Me.Tag) End If Else nid.szTip = Trim(App.ProductName) & Chr(0) End If Shell_NotifyIcon NIM_ADD, nid End Sub
Private Sub DestroyTrayIcon() Shell_NotifyIcon NIM_DELETE, nid End Sub
Private Sub RefreshTrayIcon() nid.hIcon = Me.Icon If Trim(Me.Tag) <> "" Then If Right(Me.Tag, 1) <> Chr(0) Then nid.szTip = Trim(Me.Tag) & Chr(0) Else nid.szTip = Trim(Me.Tag) End If Else nid.szTip = Trim(App.ProductName) & Chr(0) End If Shell_NotifyIcon NIM_MODIFY, nid End Sub
Private Sub Form_Load() Me.Hide Me.Icon = Picture1.Picture DoEvents CreateTrayIcon End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) DestroyTrayIcon End End Sub
'Josefh Hennyere
|
|
|
|
|