Article View: comp.os.ms-windows.programmer.tools.mfc
Article #136Re: How to Kill a Tray icon from an another application ?
From: CG
Date: Thu, 23 Nov 2000 00:00
Date: Thu, 23 Nov 2000 00:00
106 lines
4969 bytes
4969 bytes
Well, I've found the solution...
First, retrieve the Window which manages the callback of the tray. (Use
Spy++, if you have no idea, it's often the "About box" displayed when you
click on the trayicon). Then just reminds the title of this Window; we
called it "Title TrayIconWindow" in the sample below. Retrieve the value of
the ID of the TrayIcon (Use spy++...) called ID_TrayIcon in the sample
below...
Then retrieve the handle of the window from your application, before killing
the application which creates the TrayIcon like that :
HwndTrayIconWnd = FindWindow (NULL, "Title TrayIconWindow");
Kill the application then...
NOTIFYICONDATA nd;
nd.cbSize = sizeof (nd);
nd.hwnd = HwndTrayIconWnd;
nd.uID = ID_TrayIcon;
ShellNotify_Icon (NIM_DELETE, &nd);
It woks whatever the OS...
Hope It will help...
Chris.
"Aurelian Coasan [MS]" <mtsis@microsoft.com> a οΏ½crit dans le message news:
enTSzhLUAHA.250@cppssbbsa02.microsoft.com...
> Hi!
>
> an interesting question; so i took a look at it.
> in my tests neither adding and deleting a new status area icon nor
> invalidating the status area window worked.
> so i came up with the following solution. (it seems a little unprecise,
but
> i'll append also one of the attempts i made, to show that the "normal",
> more professional trials didn't work.) the one i show after the solution,
> which uses TB_GETITEMRECT doesn't work (the message returns TRUE, but the
> contents of the RECT are not valid, hence this not very precise variant i
> came up with eventually - but try it, i tested it on win2k and didn't
> encounter problems, but who knows..., i don't guarantee anything - it
could
> hide surprises):
> =========================================
> solution:
>
> HWND hwndTaskBar, hwndTrayWnd, hwndTrayToolBar;
> BOOL res;
> hwndTaskBar = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL);
> hwndTrayWnd = FindWindowEx (hwndTaskBar , NULL, "TrayNotifyWnd", NULL);
> hwndTrayToolBar = FindWindowEx(hwndTrayWnd, NULL, "ToolbarWindow32",
NULL);
> RECT rTrayToolBar;
> ::GetClientRect(hwndTrayToolBar, &rTrayToolBar);
> for (WORD x = 0; x < rTrayToolBar.right ; x += 8)
> for (WORD y = 0; y < rTrayToolBar.bottom ; y +=8)
> ::SendMessage(hwndTrayToolBar , WM_MOUSEMOVE, 0,
> MAKELPARAM(x,y) );
> ==========================================
> this doesn't work (at least on win2k not):
> LONG lNrButtons = (LONG)::SendMessage(hwndTrayToolBar, TB_BUTTONCOUNT,
> 0, 0);
> RECT rButton;
> for (LONG i = 0; i < lNrButtons; i++)
> {
> res = ::SendMessage(hwndTrayToolBar,
> TB_GETITEMRECT,
> (WPARAM) i,
> (LPARAM) &rButton);
> ::SendMessage(hwndTrayToolBar,
> WM_MOUSEMOVE,
> 0,
> MAKELPARAM
> (
> (WORD) ((rButton.left + rButton.right) /2),
> (WORD) ((rButton.top + rButton.bottom ) / 2)
> )
> );
> }
>
> hth,
> -aurelian
>
> "CG" <cgranottier@nospamseres.fr> schrieb im Newsbeitrag
> news:FU8R5.763$%o6.2878648@nnrp3.proxad.net...
> > In my program, I make a system kill of an application that have an icon
> tray
> > in the traybar...
> > But the problem is that the icon isn't kill properly by the killed
> > application to the task icon remains here.
> > The only way to delete the tray icon is to move the mouse over the tray
> > icon, but I'd like to di it in my programm after I kill the application.
> > I try something like that :
> >
> > hwndTaskBar = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL);
> > hwndTrayWnd = FindWindowEx (hwndTaskBar , NULL, "TrayNotifyWnd", NULL);
> >
> > and then SendMEssage (hwndTrayWnd , WM_PAINT, 0, 0);
> >
> > but it doesn't work.
> > Any idea ???
> > Chris.
> >
> >
>
>
Technical Details
Message-ID:
<8v6T5.648$NT.1224749@nnrp2.proxad.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<FU8R5.763$%o6.2878648@nnrp3.proxad.net> <enTSzhLUAHA.250@cppssbbsa02.microsoft.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1138df,d00bad325b1977a5 X-Google-Attributes: gid1138df,public X-Google-Thread: 113dfb,d00bad325b1977a5 X-Google-Attributes: gid113dfb,public X-Google-Thread: 104d65,d00bad325b1977a5 X-Google-Attributes: gid104d65,public X-Google-Thread: f5082,d00bad325b1977a5 X-Google-Attributes: gidf5082,public X-Google-Thread: 1053e6,d00bad325b1977a5 X-Google-Attributes: gid1053e6,public From: "CG" <cgranottier@nospamseres.fr> Subject: Re: How to Kill a Tray icon from an another application ? Date: 2000/11/23 Message-ID: <8v6T5.648$NT.1224749@nnrp2.proxad.net> X-Deja-AN: 697014212 References: <FU8R5.763$%o6.2878648@nnrp3.proxad.net> <enTSzhLUAHA.250@cppssbbsa02.microsoft.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Complaints-To: abuse@proxad.net X-Trace: nnrp2.proxad.net 974976068 213.228.51.247 (Thu, 23 Nov 2000 11:41:08 CET) Organization: Guest of ProXad - France X-MSMail-Priority: Normal NNTP-Posting-Date: Thu, 23 Nov 2000 11:41:08 CET Newsgroups: comp.os.ms-windows.programmer.tools.mfc,comp.os.ms-windows.programmer.win32,fr.comp.os.ms-windows.programmation,microsoft.public.fr.vc,microsoft.public.vc.mfc