Results 1 to 8 of 8

Thread: [RESOLVED] System Tray Icon Goes Black After Standby Mode

  1. #1

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Resolved [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

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    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.

  4. #4

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    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.

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: System Tray Icon Goes Black After Standby Mode

    Quote Originally Posted by Niya View Post
    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.

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: System Tray Icon Goes Black After Standby Mode

    Resource files are compiled into EXEs.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    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
  •  



Click Here to Expand Forum to Full Width