Solved

Repainting system tray

Posted on 1997-12-30
7
539 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
Comment Utility
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
Comment Utility
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
Comment Utility
we have the same problem.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Expert Comment

by:alexo
Comment Utility
Assuming you only have one tray (you *can* have more...)

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


0
 

Author Comment

by:danbind
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

12 Experts available now in Live!

Get 1:1 Help Now