🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.tools.mfc
Article #139

Re: How to Kill a Tray icon from an another application ?

#139
From: Frank Ostrowski
Date: Mon, 20 Nov 2000 00:00
83 lines
4411 bytes
On Fri, 17 Nov 2000 18:03:06 +0100, "Aurelian Coasan [MS]"
<mtsis@microsoft.com> wrote:

>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) );
>==========================================
[cut]
>-aurelian
>
I am not very sure, why this is not working on my Win98SE, But with Spy++ I
looked at the Shell_TrayWnd and found no ToolbarWindow32 - only a
TrayNotifyWnd. The programm above can be made a little more robust with an
if(::GetClientrect()) (just a quick check, if the hWnd is valid). Otherwise
the SendMessage may take some time.
(Conversion back to C++ should consist only in :: in front of API-calls)

/* Kills defunct TrayIcons
Quelle:
    "Aurelian Coasan [MS]" <mtsis@microsoft.com>
    Subject: Re: How to Kill a Tray icon from an another application  ?
    Date: Fri, 17 Nov 2000 18:03:06 +0100
    comp.os.ms-windows.programmer.win32
    Modified Frank Ostrowski
    1st: C++ -> C
    2nd there is no ToolbarWindow32 (Win98SE)
    To be (more or less) independent on child class names and z-order
    I use EnumChildWindows: simply redo for all childs
   somewhat timeconsuming for the Start-Button and ReBarWindow32 -
   therefore the optional extra check in the __enumFunc.
   will do moving the mouse across TrayClock - doesnot take as long
*/

static BOOL __enumFunc(HWND hWnd, LPARAM lp0)
{
    RECT R;
    int x, y;
    char buf[8];
    if(GetClientRect(hWnd, &R)) {
        GetClassName(hWnd, buf, sizeof(buf));
        //these two lines work only for Tray.. or Tool...class
        if(buf[0] != 'T') return TRUE;
        for(x = 0; x < R.right ; x += 8)
            for(y = 2; y < R.bottom ; y +=8)
              SendMessage(hWnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
        //There is a reason for this extra y loop: assuming multiple old
        //trayicons, each sendmessage kills one icon, the next message
        //will hit the same x-position, and kill the next icon
    }
    return TRUE;
}

void FixTrayIcons(void)
{
    HWND    hwndTaskBar;
    hwndTaskBar = FindWindow("Shell_TrayWnd", NULL);
    if(hwndTaskBar)
        EnumChildWindows(hwndTaskBar, __enumFunc, 0);
}
Technical Details
Message-ID: <3a1901ef.5044652@news.cis.dfn.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <FU8R5.763$%o6.2878648@nnrp3.proxad.net> <enTSzhLUAHA.250@cppssbbsa02.microsoft.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1138df,d00bad325b1977a5
X-Google-Attributes: gid1138df,public
X-Google-Thread: 1053e6,d00bad325b1977a5
X-Google-Attributes: gid1053e6,public
X-Google-Thread: f5082,d00bad325b1977a5
X-Google-Attributes: gidf5082,public
X-Google-Thread: 113dfb,d00bad325b1977a5
X-Google-Attributes: gid113dfb,public
X-Google-Thread: 104d65,d00bad325b1977a5
X-Google-Attributes: gid104d65,public
From: fr-ost@web.de (Frank Ostrowski)
Subject: Re: How to Kill a Tray icon from an another application  ?
Date: 2000/11/20
Message-ID: <3a1901ef.5044652@news.cis.dfn.de>
X-Deja-AN: 695709454
References: <FU8R5.763$%o6.2878648@nnrp3.proxad.net> <enTSzhLUAHA.250@cppssbbsa02.microsoft.com>
X-Trace: fu-berlin.de 974718402 3002072 62.54.216.204 (16 [57564])
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