• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

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?
0
ajtech
Asked:
ajtech
  • 4
  • 2
1 Solution
 
VbmasterCommented:
I guess you are using the Shell_NotifyIcon API to show the traybar icon? If this is the case you can simply set the hIcon property of the user-defined type NOTIFYICONDATA and execute the API with the parameter NIM_MODIFY to update the settings for the trayicon.

  Const NIM_MODIFY = &H1

  Shell_NotifyIcon NIM_MODIFY, TrayIcon
0
 
ajtechAuthor Commented:

So I would have two trayIcons,
trayIcon1, and trayicon2?
and switch between them?
0
 
VbmasterCommented:
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(ResourceIconNumber, vbResIcon)
  TrayIcon.hIcon = frmMain.picTray.MouseIcon

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ajtechAuthor Commented:
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
0
 
VbmasterCommented:
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.
0
 
VbmasterCommented:
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. ;)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now