ajtech
asked on
Changing Pictures ina a Tray Icon
Hello, I have successfully made a Visual Basic program that executes in the system tray, my icon is visible in the tray, etc. But now I would like to change the icon to show a crossed out icon when my app is not activated , and then to show the normal icon when it is activated. I can do everything but change the icons. Can anybody help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I use this code to read a icon from a resource files. Because the hIcon property demands a picturebox of a type 'Icon' I had to do asssign the icon to the MouseIcon property of my traybar picturebox.
frmMain.picTray.MouseIcon = LoadResPicture(ResourceIco nNumber, vbResIcon)
TrayIcon.hIcon = frmMain.picTray.MouseIcon
frmMain.picTray.MouseIcon = LoadResPicture(ResourceIco
TrayIcon.hIcon = frmMain.picTray.MouseIcon
ASKER
I Tried It and It worked!
Here is My Code!!
I have two picture boxes,
one checked and one not
"Me" is my invisible form
Thanks a lot!
Case 1:
Activated = False
Set Me.Icon = Picture2.Picture
NID.hIcon = Me.Icon
Shell_NotifyIcon NIM_MODIFY, NID
Case 2:
Activated = True
Set Me.Icon = Picture1.Picture
NID.hIcon = Me.Icon
Shell_NotifyIcon NIM_MODIFY, NID
Here is My Code!!
I have two picture boxes,
one checked and one not
"Me" is my invisible form
Thanks a lot!
Case 1:
Activated = False
Set Me.Icon = Picture2.Picture
NID.hIcon = Me.Icon
Shell_NotifyIcon NIM_MODIFY, NID
Case 2:
Activated = True
Set Me.Icon = Picture1.Picture
NID.hIcon = Me.Icon
Shell_NotifyIcon NIM_MODIFY, NID
No u only have one but the NIM_MODIFY parameter will tell the trayicon to just redraw. This will not create a new trayicon. But this means that you will have to save the NOTIFYICONDATA variable which you use when you create the trayicon (for the program to know what icon to update.. it reads the uId property and checks the Task ID I guess.
Nice. One idea would be to try the MouseIcon property instead of the extra picturebox, but that's only if you want to cut down on the number of controls needed. ;)
ASKER
So I would have two trayIcons,
trayIcon1, and trayicon2?
and switch between them?