How do I add an animated ico into the systray?
I appreciate any time or effort spent on your replies,
Daniel christie
Printable View
How do I add an animated ico into the systray?
I appreciate any time or effort spent on your replies,
Daniel christie
You have to do some subclassing, or download my traycontrol that is not ready yet. Subclassing is somwhat dangerous for your vb and crashes it for me about 30 times a day, so my traycontrol will take some time to be finnished.
The icon can be animated by modifying a picture added to imagelistcontrol, extracting it and set it to the tray.
you don't have to subclass or use a activex control. all you have to do is add an icon to the system tray by using the code below and set a timer to change it for each frame you have in your animation. here's the code:
In the declarations area:
on a form put a control array of as many picture boxes as you have frames in your animation (let's say 5 here). in each picture box, IN ORDER, place the frames of the animation. so in Picture(0) would be frame 1 of the animation, in Picture(1) would be frame 2, etc.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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA"_
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const WM_RBUTTONUP = &H205
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private tTrayIcon As NOTIFYICONDATA
in the Form_load() sub:
now in a timer put this code:Code:Dim i as integer
i = 0
now set the timer to however fast you want the animation to appear running.Code:'play the animation and loop it when it is done
'the animation has 5 frames, picture(0) up to picture(4)
i = i + 1
if i > 4 then i = 0
With tTrayIcon
.hIcon = Picture(i).Picture
.hwnd = Picture(i).hwnd
.szTip = Caption & Chr(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
.cbSize = Len(tTrayIcon)
End With
'add the icon to the system tray
Shell_NotifyIcon NIM_ADD, tTrayIcon
that should work. sorry if it doesn't. i haven't tested this yet. it's just an idea. and it may not be the most efficient way to do this but who knows? give it a shot. lemme know what turns out. take care.
[Edited by funkheads on 03-31-2000 at 02:57 PM]
No, you have to subclass to get the event when you click on the icon, so that it makes a popupmenu. Damn, that was not the qwestion here, I was more into my own project when I answered in my last post. Sorry about that. And setting that picture to the icon property, I don't know if it works. But extracting it from an imagelistcontrol will give true icon.
i am afraid again i must prove you wrong. you do not have to subclass to get a popup menu to popup when clicked. here's the code:
[Code:Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_RBUTTONUP
frmMenu.PopupMenu mnuMain
Case WM_LBUTTONUP
Exit Sub
'or whatever code you may need when the user left-clicks on the icon
End Select
End Sub
[Edited by funkheads on 04-01-2000 at 12:47 PM]
Im still talking about the tray icon, not any picturebox.
Hmm I saw this a while ago without having to subclass (I think) or any other garbage and it is just like like funk heads said let me see if I can find that demo project. They set it up a little wierd so I changed it to fit my project so the first link is theres and the second link is mine so mix them and you should have what you are looking for.
http://www.angelfire.com/yt/PITBULLCJR/tray.zip
http://www.angelfire.com/yt/PITBULLCJR/SystemTray.zip
Hope this helps!!
kedaman -
i am also talking about the tray icon. in order to get the popup menu to popup when you click on the system tray icon using my code you need to bind the click event to the picturebox_mousemove function. do me a favor and put my code into a VB project and see if it works. i did and it works perfectly. so before you make anymore comments try it. thanks.