How to get a TrayIcon handle?

delphi package - easy access to kernel objects etc.
Post Reply
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

How to get a TrayIcon handle?

Post by nildo »

Hello Madshi and everyone!

Madshi, are you able to tell me the way you do to get a trayicon handle of another process?

Thank you!
Shenck
Posts: 15
Joined: Tue Apr 19, 2005 2:59 pm

Post by Shenck »

var
ico:Ticon;
begin
ico:=Ticon.Create;
ico.Handle:=Process('explorer.exe').Icon;
//rest of code
ico.free;
end;
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Shenck wrote:var
ico:Ticon;
begin
ico:=Ticon.Create;
ico.Handle:=Process('explorer.exe').Icon;
//rest of code
ico.free;
end;
I mean... How does Process('explorer.exe').Icon works internaly?
neji
Posts: 155
Joined: Wed Mar 09, 2005 11:39 am
Contact:

Post by neji »

use the source luke , hehe

I don't know if I'm allowed to post madshi's code here but I think this is the most important part of the function

Code: Select all

c1 := SHGetFileInfo(pchar(file_), GetFileAttributes(pchar(file_)), sfi, sizeOf(sfi), c1);
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Are we talking about the tray icon handle or about the exe icon shown in the explorer list?
Shenck
Posts: 15
Joined: Tue Apr 19, 2005 2:59 pm

Post by Shenck »

Code: Select all

function GetTrayIcon(PID:dword):cardinal;
var
 exe:string;
 i:integer;
begin
  exe:=process(pid).ExeFile;
  Result:=0;
  for i:=0 to TrayIcons().ItemCount-1 do
  begin
   if  TrayIcons().Items[i].Window.OwnerProcess.ExeFile=exe then
    begin
     Result:=TrayIcons().Items[i].Icon;
     exit;
    end;
  end;
end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Shenck, you can have that easier:

Code: Select all

function GetTrayIcon(PID:dword):cardinal;
begin
  result := Process(PID).TrayIcons[0].Icon;
end;
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

madshi wrote:Are we talking about the tray icon handle or about the exe icon shown in the explorer list?
TrayIcon.

I would like to know how does it works internaly. How do you get the handle. I'm just curious! But if it's secret, I understand! :)

See you!
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Oh, it's quite complicated - and it differs depending on the OSs!

Check out this one to find more information about it:

http://members.fortunecity.com/nickrepin/winprog.html
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

madshi wrote:Oh, it's quite complicated - and it differs depending on the OSs!

Check out this one to find more information about it:

http://members.fortunecity.com/nickrepin/winprog.html
THank you!
neji
Posts: 155
Joined: Wed Mar 09, 2005 11:39 am
Contact:

Post by neji »

http://www.delphipraxis.net/topic44544_ ... t=trayicon

maybe this can help you , too (look at the attachment in the second post)
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Nice! THank you people!
Post Reply