Solved

Repainting system tray

Posted on 1997-12-30
7
546 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

18 Experts available now in Live!

Get 1:1 Help Now