i want my program to be running all the time, but be minimized to the SysTray, does anyone know how do do that, and open it when it is double clicked? thanks in advance:)
Printable View
i want my program to be running all the time, but be minimized to the SysTray, does anyone know how do do that, and open it when it is double clicked? thanks in advance:)
VB Code:
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 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_RBUTTONUP = &H205 Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean Dim TrayI As NOTIFYICONDATA Private Sub Form_Load() TrayI.cbSize = Len(TrayI) 'Set the window's handle (this will be used to hook the specified window) TrayI.hWnd = pichook.hWnd 'Application-defined identifier of the taskbar icon TrayI.uId = 1& 'Set the flags TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE 'Set the callback message TrayI.ucallbackMessage = WM_LBUTTONDOWN 'Set the picture (must be an icon!) TrayI.hIcon = imgIcon(2).Picture 'Set the tooltiptext TrayI.szTip = "Recent" & Chr$(0) 'Create the icon Shell_NotifyIcon NIM_ADD, TrayI Me.Hide End Sub Private Sub Form_Unload(Cancel As Integer) 'remove the icon TrayI.cbSize = Len(TrayI) TrayI.hWnd = pichook.hWnd TrayI.uId = 1& Shell_NotifyIcon NIM_DELETE, TrayI End End Sub Private Sub mnuPop_Click(Index As Integer) Select Case Index Case 0 MsgBox "KPD-Team 1998" + Chr$(13) + "URL: [url]http://www.allapi.net/[/url]" + Chr$(13) + "E-Mail: [email][email protected][/email]", vbInformation + vbOKOnly Case 2 Unload Me End Select End Sub Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Msg = X / Screen.TwipsPerPixelX If Msg = WM_LBUTTONDBLCLK Then 'Left button double click mnuPop_Click 0 ElseIf Msg = WM_RBUTTONUP Then 'Right button click Me.PopupMenu mnuPopUp End If End Sub Private Sub Timer1_Timer() Static Tek As Integer 'Animate the icon Me.Icon = imgIcon(Tek).Picture TrayI.hIcon = imgIcon(Tek).Picture Tek = Tek + 1 If Tek = 3 Then Tek = 0 Shell_NotifyIcon NIM_MODIFY, TrayI End Sub
or see http://www.vb-world.net/tips/tip61.html
Use this:
VB Code:
Private WithEvents TI As cTrayIcon Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = vbFormControlMenu Then 'I don't want to terminate the app Set TI = New cTrayIcon With TI .SetPct pctTray .CreateIcon "This is my app" End With Me.Hide Cancel = 1 End If End Sub Private Sub TI_TrayIconDoubleCLick() TI.DeleteIcon Set TI = Nothing Me.Show End Sub Private Sub Form_Unload(Cancel As Integer) TI.DeleteIcon Set TI = Nothing End Sub
pctTray is a picturebox (invisible) with the icon you want to show in the Systray.
mc Brain,
what is or where do I find cTrayIcon? I'm assuming it's a class that I need to reference.
I got it
It's a Class I created, based on some examples I found over here... and I guess you've already found it attached on my previous reply.Quote:
Originally posted by Jennifer_R
mc Brain,
what is or where do I find cTrayIcon? I'm assuming it's a class that I need to reference.
If you all think this will help you, I've written a wrapper to send forms to the system tray.
I have it attached.
On your form, make a non-visible menu titled:
trayPopup
(no mnu prefix).
Then, to add the form to the system tray, call:
GotoTray Me
The first time (like on form load)
And then to actually show it in the system tray any time other than the first (although doing it again does not hurt):
ShowInTray Me, True
And to hide it from the tray (like in the form_queryUnload function):
ShowInTray Me, False
Also, make sure that you onload the tray icon before exiting the program or a ghost will remain in the tray.
Umm, forgot to actually attach the file (whoops)
Don't you need to add the call to CheckTray sub on the MouseDown event or similar as well to get the popmenu shown??
** Looks around nervously **
Umm yeah, I should probably comment my code better:
I'm pretty sure that's everything (now)Code:Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If lngMsg = WM_LBUTTONDBLCLICK Or lngMsg = WM_RBUTTONUP Then
' tmp = tmp
End If
CheckTray Me, lngMsg, blnFlag, result
End Sub
Another point:
The name of the form will be the tool-tip for the tray icon.
You could use its tag instead, just in case you want another tooltip for the icon.Quote:
Originally posted by Lord_Rat
Another point:
The name of the form will be the tool-tip for the tray icon.