Solved

Repainting system tray

Posted on 1997-12-30
7
541 Views
Last Modified: 2013-12-03
Greetings.  How do you make Win95 repaint the system tray?  I have some custom apps that do not properly remove their system tray icons when exiting, although if you subsequently wave the cursor over them in the system tray, they are deleted.  This makes the user think that the app is still running, when it is not.  I do not have the liberty to rewrite those apps, but I can put a periodic tray repaint in a new app that I am writing.  Doing an Invalidate(NULL, NULL, TRUE) to repaint the entire desktop doesn't do the trick.  Any suggestions? Thanks in advance.
0
Comment
Question by:danbind
7 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1409724
First of all Do you call Shell_NotifyIcon(NIM_DELETE, ...) to remove icon. If you do and it doesn't help you can erase background in system tray only. It has unique class name TrayNotifyWnd and you can use FindWindow with this clss name to obtaing a window handle.
0
 

Author Comment

by:danbind
ID: 1409725
Thanks for the info.  This seems like it would work, but I believe the problem is this:  even on a repaint, the system tray thinks that the bogus icon should remain, as it was never properly deleted with the Shell_NotifyIcon(NIM_DELETE,...) message.  Upon return from a screen saver, the icon is redrawn.  When you move the cursor over the bogus icon, and the system tray does a callback to get the tooltip caption, it doesn't get one, so it deletes the icon.  You can test this by modifying a program that uses a system tray icon so that it doesn't delete its icon on exiting.  Run it, terminate it from the task list using CTRL+ALT+DEL, and observe.  It seems like one approach would be to ask the system tray to ping all of its icons for valid callback responses (but I can't find any documentation on this).  I'm basically perplexed--it seems like there should be a way to do this.
0
 
LVL 7

Expert Comment

by:faster
ID: 1409726
we have the same problem.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:alexo
ID: 1409727
Assuming you only have one tray (you *can* have more...)

HWND hw = FindWindow("Shell_TrayWnd", NULL);


0
 

Author Comment

by:danbind
ID: 1409728
Yes, this is true, and thanks for the help.  This is the answer to the question that I asked, but I guess I asked it wrong (see previous comments).  Restating, it is this:  How do you delete orphaned icons from the system tray, or force the system tray to validate them?  I would like to be able to split the points between galkin and alexo, as the answers are correct.  I would still like a solution to my problem (if one exists), however.
FYI, I found a posting in DejaNews by Jonathan Edwards showing how to find the number of icons in the tray, although I haven't tried it out.
0
 
LVL 1

Accepted Solution

by:
_Zaphod earned 100 total points
ID: 1409729
Windows deletes an orphaned icon if you put the cursor above it and wait for the Tip to come.
My guess is that if you emulate a click on the orphaned icon, Windows will understand its parent has died and will remove it. Use WM_CLICK, WM_LBUTTONDOWN or WM_LBUTTONUP, I guess, on the tray window (finding it as alexo told you), with the parameters pointing to the icon. Shouldn't be too hard.
0
 

Author Comment

by:danbind
ID: 1409730
I was hoping that there might be another way, as I'm never comfortable imitating user input--but this works well enough, so I guess you get the cigar.  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now