I remember an article i posted ages and ages ago. It was about popup menus in VB. I just wondered if anyone has figured out a way to get it to dissappear when it loses focus. Because i have to stick a cancel button on them to make them dissappear when i change my mind. It bugs me!
Here is a wrapper I wrote for system tray icons; you can use it for your app, I won't mind.
To use it:
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 unload the tray icon before exiting the program or a ghost will remain in the tray.
Also, on the form, you need:
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
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
thats pretty neet. Not tried it yet mind you. One problem with it i can see is i will have to modify it a lot suppose, just looking at a glance. The reason is I have customised my system tray bas file to handle animated system tray icons. Well heres mine anyways, take a look, not as advanced as your though
If you change the icon for the form, it will change the icon for the tray. Thus, if you want to have an animated icon, you can change the icon to the next frame on a timer event.
I downloaded your code, but I cannot see how you are currently implementing animated icons.
If you could give me some code, I could probably figure out what you are doing and then add that functionality to mine (which I agree, could be handy)
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
you just need to add a timer for the animation you want to present. For me, i am building a real simple email notification program that doesnt use much memory, and sits in the systray (it beats having outlook open 24 7).
VB Code:
Private Sub tmrAnimateFull_Timer()
Static i As Integer
If i < 0 Then i = 0
If i > 1 Then i = 0
ModSysTrayIco imgFull(i).Picture.Handle
i = i + 1
End Sub
that one just makes the mail box icon flash different colours. You have to have the images in a resource or as image arrays on the form. Unless there is an easier way. I mean, i like to embed them because it makes porting the program onto other computers a whole lot easier.
This snippet does the same, but for a more complex animation sequence.
VB Code:
Private Sub tmrAnimateCheck_Timer()
Static i As Integer
If i < 0 Then i = 0
If i > 7 Then i = 0
ModSysTrayIco imgCheck(i).Picture.Handle
i = i + 1
End Sub
Notice there are 8 frames in this animation as opposed to 2 in the last one. Still uses the same code though
Yeah that is an annoying thing, to fix it call SetForegroundWindow API before showing the PopUp, just pass it the hwnd of the owner form or i guess just one from your app.
I apologize Lord_Rat but I didn't mean any disrespect either. I was just answering the original question. I'm happy with the class I use and I used to have the same problem using the NotifyIcon bit until I did what I posted, so it worked for me and I'm just spreading the wealth, same as you. Although I like learning new things so I'll check out your code.
I have created a new version of the mdlSysTray.bas file. I hope you dont mind Lord_Rat. I have incorperated everything into this module, so the module can:
-Save the systray entries
-Restore the systray entries
-Add to the systray
-Modify the entire systray entry
-Modify the icon for the systray entry
-Modify the TTT (Tool Tip Text) for the systray entry
-Generate a Popup menu for the systray entry
-Dock a form to the systray
-Restore a form from the systray
If you think of anything else that might be usefull stick it in there too. Oh, i removed the "On Error Goto" 's because i couldnt see a use for them. If we display errors about the program crashing, the programmer will think the module caused it. I cant see how the module will cause an error, and goto's are bad practice anyways. If you can argue them back into the module go ahead and I will accept another modification.
If you do modify the module, please re-post so I can see what benefits it gives you, and to see if i can make the module more reuseable.