|
-
Oct 10th, 2012, 08:24 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] System Tray Icon Goes Black After Standby Mode
Hello, I have an application that sits in the windows system tray. This application flashes at certain intervals. The way I do this is by using a timer, and change the icon every second for a shor interval. This gives the effect of a flashing icon. All of this works good without issues. Here is where the problem starts. I noticed that if the computer goes into standby mode or hibernation and then starts again, if an icon hadn't previously been shown (flashing hadn't occured yet) the icon that hadn't been shown before standby-mode shows as black. The shape of the icon is correct but is black. The current icon that the application was displaying in the system tray before the stand-by mode shows correct color and all. Anybody have any idea what the issue could be?
Keep in mind that the icons to be displayed are stored in image objects that are on the main form of the application. I tried putting the icons into an imagelist and still had the same issue.
This is how I flash the icon in the system tray using an ImageList object. The same occurs using an Image object.
Code:
nid.hIcon = Me.imgIcon.ListImages(0).Picture
Shell_NotifyIcon NIM_MODIFY, nid
nid.hIcon = Me.imgIcon.ListImages(1).Picture
Shell_NotifyIcon NIM_MODIFY, nid
Thanks for any insight in what may be causing this.
Last edited by Hassan Basri; Oct 15th, 2012 at 10:19 AM.
Reason: Issue was not resolved
-
Oct 11th, 2012, 03:44 AM
#2
Re: System Tray Icon Goes Black After Standby Mode
Hmmm this is a strange bug. I'm going to assume that when you reawaken the system from sleep mode, that your timers are still working correctly. I'll proceed on that assumption:
I'll take a purely instinctive stab here and say that what every sleep mode does is mucking up the image. GDI objects are maintained by GDI32.Dll. Icons, Bitmaps, Pens and Brushes are all GDI objects. These objects are stored in memory and are referenced by handles. When going into sleep mode its possible that these objects are flushed from memory onto the disk or they are re-arraged in some way and when the system awakes it doesn't restore it properly....or something to that effect. Try to confirm this by reloading the image from what ever image file you got it from after awaking the system.
If that doesn't work, try refreshing by using NIM_DELETE and re-adding by NIM_ADD then go back into your normal NIM_MODIFY timer loop.
-
Oct 11th, 2012, 10:23 AM
#3
Thread Starter
Hyperactive Member
Re: System Tray Icon Goes Black After Standby Mode
Thanks Niya, the NIM_DELETE and NIM_ADD didn't work.
I did find the solution however. Instead of putting the icons in an Image or ImageList object, I put the icons in a PictureBox object. Now everything works correctly even after standby mode. Thanks again for your assistance Niya.
-
Oct 15th, 2012, 10:19 AM
#4
Thread Starter
Hyperactive Member
Re: System Tray Icon Goes Black After Standby Mode
I was msitaken this is not resolved. Even when using a Picturebox object I am still getting the black icon. Does anybody know if there is a way of reloading the icon into memory from an Image or Picturebox object? I tried the NIM_DELETE and NIM_ADD and the NIM_UPDATE but nothing is working. Thanks.
-
Oct 16th, 2012, 03:56 AM
#5
Re: System Tray Icon Goes Black After Standby Mode
Where do you get the icon from ? I'm assuming it comes from a file, if so try reloading it from disk.
-
Oct 16th, 2012, 09:21 AM
#6
Thread Starter
Hyperactive Member
Re: System Tray Icon Goes Black After Standby Mode
 Originally Posted by Niya
Where do you get the icon from ? I'm assuming it comes from a file, if so try reloading it from disk.
Hello Niya, I wanted to avoid that to keep the icons inside the executable. I am thinking I may try to store the icons in a ressource file and load from there. I'll let you know if that works.
-
Oct 16th, 2012, 10:50 AM
#7
Re: System Tray Icon Goes Black After Standby Mode
Resource files are compiled into EXEs.
-
Oct 17th, 2012, 10:18 AM
#8
Thread Starter
Hyperactive Member
Re: System Tray Icon Goes Black After Standby Mode
Ok, this finally solved the issue. Instead of storing the icons in image, picturebox or imagelist objects I stored the image in a ressource file. Now icons never turn black. Here is what the code looks like now:
Code:
nid.hIcon = LoadResPicture("ICON_FLASH", vbResIcon)
Shell_NotifyIcon NIM_MODIFY, nid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|