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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ajtechAuthor Commented:

So I would have two trayIcons,
trayIcon1, and trayicon2?
and switch between them?
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

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
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. ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.