Thread: Systemtray Problem

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Systemtray Problem

    Hi,

    This is my code:

    Code:
    case WM_CREATE:
    		
    				hInst = (HINSTANCE)GetWindowLong(NULL, GWL_HINSTANCE);
    				hmenu = LoadMenu(hInst,MAKEINTRESOURCE(IDR_SYSMENU));
    				hmenu = GetSubMenu(hmenu,0);
    
    				Nicon.cbSize = sizeof(NOTIFYICONDATA);	
    				Nicon.hWnd = hWnd;	
    				Nicon.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
    				Nicon.hIcon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1),
    					IMAGE_ICON,16,16,LR_DEFAULTCOLOR); 								
    				Nicon.uCallbackMessage = WM_TRAYMESSAGE;
    				Nicon.uID = ICONIDENT;
    				wcscpy(Nicon.szTip, _T("Check"));
    				Shell_NotifyIcon(NIM_ADD, &Nicon);
    			break;
    
    case WM_DESTROY:
             Shell_NotifyIcon(NIM_DELETE, &Nicon);	
    	 PostQuitMessage(0); 
    	 return 0;
    The problem i am having is that when my program closes, the tray icon is not removed, and it is left in the tray, until i move my mouse over it then it is removed. Any ideas what i have done wrong?

    Thanks
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    I have the same system tray problem. This is a known bug in the Win32 GUI. Unfortunately, Win32 is an extremely low MS priority. So, I don't believe this problem will ever be resolved.

    Spent many, many hours Googling for a resolution and came up empty. If you find a work around, please post it.

  3. #3
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Tell me if this helps...

    Code:
    case WM_DESTROY:
             SetForegroundWindow( hwnd );
             Shell_NotifyIcon(NIM_DELETE, &Nicon);	
    	 PostQuitMessage(0); 
    	 return 0;

  4. #4
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Quote Originally Posted by Dante Shamest
    Tell me if this helps...

    Code:
    case WM_DESTROY:
             SetForegroundWindow( hwnd );
             Shell_NotifyIcon(NIM_DELETE, &Nicon);	
    	 PostQuitMessage(0); 
    	 return 0;
    Sadly that didnt help , but i managed to fix the problem by moving my code out of WM_CREATE into my WinMain() function, and i made the notifyicon structure global then just added the icon in WM_CREATE, by doing this in combination with having Shell_NotifyIcon(NIM_DELETE, &Nicon); inside WM_DESTROY the icon is now removed fine
    TNT
    You Can Stop Me, But You Cant Stop Us All

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by BobS0327
    I have the same system tray problem. This is a known bug in the Win32 GUI. Unfortunately, Win32 is an extremely low MS priority. So, I don't believe this problem will ever be resolved.
    Except that no real profession software experiences this alleged 'bug'. There is no such 'bug' - there's failing to clean up and remove your systray icon.

    (TNT): Does your NOTIFYICONDATA structure contain any information, or random garbage? You'll need to fill out at least the uID & hWnd members for removal to work. (Perhaps more) (Is Shell_NotifyIcon() returning success? No...)

    All I can see from your code post is Nicon being filled out in WM_CREATE. If you've declared Nicon as a normal variable ( ie, NOTIFYICONDATA Nicon; ) then it contains no real data.

    1) Show us how/where you declare Nicon.
    2) Make sure that at the call with NIM_DELETE, that the uID & hWnd members are valid.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    but i managed to fix the problem by moving my code out of WM_CREATE into my WinMain() function, and i made the notifyicon structure global then just added the icon in WM_CREATE, by doing this in combination with having Shell_NotifyIcon(NIM_DELETE, &Nicon); inside WM_DESTROY the icon is now removed
    (TNT)

    This does seem to work for me. I don't know how many times I've single stepped thru my code with a debugger to no avail. It even got to the point where I was questioning my debugger. So, I sent the code to an associate programmer for a peer review and she experienced the same thing. Between Googling and single stepping the code, I have quite a bit of time invested in this problem.

    THANX!!!!
    Last edited by BobS0327; 06-18-2006 at 07:38 AM.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Except that no real profession software experiences this alleged 'bug'. There is no such 'bug' - there's failing to clean up and remove your systray icon
    .

    The purpose of my Google searches was not to identify "real profession" software that has this False Icon bug but I did come across users complaining about this quirk with Instant Messenger and Microsoft Active Sync version 4.1 and a few other really obscure "real profession" software from HP and others.

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    iTunes has the False Icon Bug if I close it during a high load time, Java has this bug also from time to time. So your "real profession software" theory is off.

  9. #9
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    If explorer.exe is terminated, reason doens't matter in this exmaple, and explorer.exe is running again after it was terminated, your icon would be gone from the Notification Area, do you know how to fix this, TNT?

    -Awnser: Check if you can find the Taskbar window, if not, explorer is probably gone, now check if it is back again, if so re-add your icon and done, cheers.

  10. #10
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hmm im not to sure what you mean Yuri, If a process is terminated directly, then the tray icon still remains, I dont think this can be fixed, because the said program does not go through its cleanup routines which will include removing the tray icon, as a result its left behind (sometimes anyway...)

    However, it does seem like a bug to me because i would have thought if the parent process to the tray icon no longer exists then windows should remove the icon automatically.

    Anyway this wasnt the problem i was having, my problem was that during a 'normal' program exit the icon was left behind, i have now fixed this by placing the code in the WinMain function.
    TNT
    You Can Stop Me, But You Cant Stop Us All

  11. #11
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    I know this isn't about the problem you had but this another problem about the systemtray icon, it is easy to fix, I'll try to explain the problem a bit better. When explorer.exe crashes or is terminated or what so ever and explorer gets executed again, so explorer.exe is running again the taskbar is recreated so the icons of other running applications need to be re-added, most programs do so, like MSN but if you don't have a code to re-add you icon, it wont be on the notification area anymore.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM