Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2006, 11:09 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default How do I hide system tray icon of another application

I need to hide the system tray icon of certain applications. Is there any way to do this with Delphi?

Help please.

thanks

========================================
A point waiting for the correct answer.

thank you

Jon
Reply With Quote
  #2  
Old 09-29-2006, 12:18 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: How do I hide system tray icon of another application

i think that is this function that you are searching..

look this other post that describe this

[link]http://www.delphipages.com/threads/thread.cfm?ID=170851&G=170849[/link]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #3  
Old 09-29-2006, 11:06 PM
kenshin1101 kenshin1101 is offline
Senior Member
 
Join Date: Mar 2006
Posts: 346
Default RE: How do I hide system tray icon of another application

why you need to do that ? Of course that post does nothing but the API Shell_NotifyIcon :
you need 2 parameter :
[DELPHI]
hWnd - Handle of the window that receives notification messages associated with an icon in the taskbar status area.

uID - Application-defined identifier of the taskbar icon.
[/DELPHI]
To do that is not simple, because IS NOT IN YOUR APPLICATION. This is in other Application.

I just give you a way to do that, (not tested - i'm too busy) :
Those code here help you "ENUM" any ICON Exists in Tray. In my application i just use to determine the position of my tray icon only. But i thinks it useful for you.
Code:
unit TrayPro;
{
  Copyright(C) 2005-2006 by Kenshin1101
  HomePage : http://kenshin1101.googlepages.com
  Email : kenshin1101@gmail.com
}
interface
uses windows, CommCtrl, SysUtils;

function FindOutPositionOfIconDirectly(const a_hWndOwner: HWND;const a_iButtonID: integer;
         var a_rcIcon : TPoint) : BOOL;
function NumberOfButton(hWndTray : HWND): integer;
function GetTrayToolbarControl: HWND;

implementation

function FindOutPositionOfIconDirectly(const a_hWndOwner: HWND;const a_iButtonID: integer;
         var a_rcIcon : TPoint) : BOOL;
var hWndTray, hWndOfIconOwner : HWND;
    dwTrayProcessID, dwBytesRead : DWORD;
    hTrayProc : THandle;
    iButtonsCount, iButton, iIconId : integer;
    lpData : Pointer;
    buttonData : TTBBUTTON;
    bIconFound : BOOL;
    dwExtraData : array[0..1] of DWORD;
    rcPosition : TPoint;
begin
    hWndTray := GetTrayToolbarControl();

    //now we have to get an ID of the parent process for system tray
    dwTrayProcessID := DWORD(-1);
    GetWindowThreadProcessId(hWndTray, dwTrayProcessID);

    //here we get a handle to tray application process
    hTrayProc := OpenProcess(PROCESS_ALL_ACCESS, False, dwTrayProcessID);

    //now we check how many buttons is there - should be more than 0
    iButtonsCount := SendMessage(hWndTray, TB_BUTTONCOUNT, 0, 0);
    //We want to get data from another process - it's not possible
    //to just send messages like TB_GETBUTTON with a locally
    //allocated buffer for return data. Pointer to locally allocated
    //data has no usefull meaning in a context of another
    //process (since Win95) - so we need
    //to allocate some memory inside Tray process.
    //We allocate sizeof(TBBUTTON) bytes of memory -
    //because TBBUTTON is the biggest structure we will fetch.
    //But this buffer will be also used to get smaller
    //pieces of data like RECT structures.
    lpData := VirtualAllocEx(hTrayProc, nil, sizeof(TTBBUTTON), MEM_COMMIT, PAGE_READWRITE);

    bIconFound := FALSE;

    for iButton := 0 to iButtonsCount - 1 do
      begin
        //first let's read TBUTTON information
        //about each button in a task bar of tray

        dwBytesRead := DWORD(-1);
        SendMessage(hWndTray, TB_GETBUTTON, iButton, LPARAM(lpData));

        //we filled lpData with details of iButton icon of toolbar
        //- now let's copy this data from tray application
        //back to our process
        ReadProcessMemory(hTrayProc, lpData, @buttonData,
                         sizeof(TTBBUTTON), dwBytesRead);

        //let's read extra data of each button:
        //there will be a HWND of the window that
        //created an icon and icon ID
        dwExtraData[0] := 0;
        dwExtraData[1] := 0;

        ReadProcessMemory(hTrayProc, Pointer(buttonData.dwData),
               @dwExtraData, sizeof(dwExtraData), dwBytesRead);

        hWndOfIconOwner := HWND(dwExtraData[0]);
        iIconId         := integer(dwExtraData[1]);

        if (hWndOfIconOwner <> a_hWndOwner) or (iIconId <> a_iButtonID) then
         begin
            { Found a Icon of other program 
              Now do what you want here...
              }

         end
        else
         begin
          //we found our icon - in WinXP it could be hidden - let's check it:
          if( buttonData.fsState and TBSTATE_HIDDEN ) > 0 then
            begin
          {
              break;
          } end;

          //now just ask a tool bar of rectangle of our icon
          SendMessage(hWndTray, TB_GETITEMRECT, iButton, LPARAM(lpData));
          ReadProcessMemory(hTrayProc, lpData, @rcPosition, sizeof(TRECT), dwBytesRead);

          MapWindowPoints(hWndTray, 0, rcPosition, 2);
          a_rcIcon := rcPosition;

          bIconFound := TRUE;
          break;
         end;
      end;

    VirtualFreeEx(hTrayProc, lpData, 0, MEM_RELEASE);
    CloseHandle(hTrayProc);

   result := bIconFound;
end;

function GetTrayToolbarControl: HWND;
var HR, return : HWND;
 function EnumChildProc(handle : HWND; var lp : Longint): boolean; stdcall;
 var s : string;
     l : integer;
  begin
    SetLength(s, 255);
    l := GetClassName(handle, PChar(s), Length(s));
    if l = 0 then
      ShowMessage('Error')
    else
    SetLength(s, l);
    if Pos('ToolbarWindow32', s) > 0 then
      begin
        lp := handle;
        result := false;
      end
    else
      result := true;
  end;
begin
 HR := FindWindow('Shell_TrayWnd', nil);
 return := 0;
 if hr <> 0 then
   EnumChildWindows(Hr, @EnumChildProc, Integer(@return));
 result := return;
end;

function NumberOfButton(hWndTray : HWND): integer;
begin
 result := SendMessage(hWndTray, TB_BUTTONCOUNT, 0, 0);
end;

end.
Reply With Quote
  #4  
Old 09-30-2006, 03:14 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: How do I hide system tray icon of another application

That looks great...however it doesn't tell me how to hide the icon?



========================================
A point waiting for the correct answer.

thank you

Jon
Reply With Quote
  #5  
Old 09-30-2006, 03:25 AM
kenshin1101 kenshin1101 is offline
Senior Member
 
Join Date: Mar 2006
Posts: 346
Default RE: How do I hide system tray icon of another application

use Shell_NotifyIcon
with NIM_DELETE & NOTIFYICONDATA structure get when "ENUM" all icon
Reply With Quote
  #6  
Old 10-02-2006, 04:38 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: How do I hide system tray icon of another application

You have to get the NOTIFYICONDATA structure and set it's
dwState flag to NIS_HIDDEN.

Remember, the app that does this MUST have access to the
other applciation's "space" so you have to inject a DLL
into the other app's memory space and do it there.

No, I do not have an example and don't have time to create
one.


MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:33 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.