Re: How to hide a GUI program with systray icon?
<j012xjj@gmail.com> wrote in message
news:1153188840.530447.326440@p79g2000cwp.googlegroups.com...
I don't think it's his program whose icon he wants to remove. He wants
to
remove a 3rd party's tray icon.
That's what I need !
Thanks for your help!
If you use Spy++ and move the mouse target over the tray icons, you will see
it is a ToolbarWindow32, owned by EXPLORER. You could send toolbar messages
to remove the button. But unless you write a DLL and inject it into the
Explorer process, you will need to use VirtualAllocEx() and
ReadProcessMemory() in order to send the toolbar messages, since the toolbar
resides in a different process than your own.
Instead of sending toolbar messages, you could call Shell_NotifyIcon to
remove the icon. But this requires the HWND owner of the icon, as well as
the icon ID. Both these are stored in the TBBUTTON::dwData of the toolbar
button:
// TBBUTTON buttonData; // this is allocated in Explorer's process
and initialized by sending TB_GETBUTTON message to the toolbar window
DWORD dwExtraData[2] = { 0,0 };
ReadProcessMemory(hExplorerProcess, (LPVOID)buttonData.dwData,
dwExtraData, sizeof(dwExtraData), &dwBytesRead);
HWND hWndOfIconOwner = (HWND) dwExtraData[0];
int iIconId = (int) dwExtraData[1];
NOTIFYICONDATA nid;
RtlZeroMemory(&nid, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(nid);
nid.hWnd = hWndOfIconOwner;
nid.uID = iIconId;
nid.uFlags = NIF_ICON;
Shell_NotifyIcon(NIM_DELETE, &nid);
Instead of all this code, which removes the tray icon once it's there, you
could use an API hook of the process you're interested in, hook
Shell_NotifyIcon(), and prevent the process from displaying the tray icon in
the first place. For this, I recommend madCodeHook at http://madshi.net
-- David