procedure THTIMainForm.enumTrayIcons;
type
TAPointer = array [0..maxInt shr 2 - 1] of Pointer;
TPAPointer = ^TAPointer;
TTrayIconInfo =
record
imageIndex: Cardinal;
case Boolean of
false: (notifyIconDataA: TNotifyIconDataA);
true : (notifyIconDataW: TNotifyIconDataW);
end;
TTrayIconsInfo =
record
iconCount: Integer;
trayIconInfos: TPAPointer;
end;
TTrayWindowInfo =
record
dummy: array [0..6] of Cardinal;
iconsInfo: ^TTrayIconsInfo;
iconList: Cardinal;
end;
var
wnd : HWND;
p1 : POINTER;
pid,
ph : cardinal;
twi : TTrayWindowInfo;
c1 : cardinal;
il : array[0..$3FF] of char;
tisi : TTrayIconsInfo;
i : integer;
tii : TTrayIconInfo;
tip : string;
ico : TIcon;
idx : integer;
begin
lv1.Items.Clear; // TListView leeren
lvimg.Clear; // TImageList leeren
lv1.Items.BeginUpdate;
wnd := FindWindowEx(FindWindow('Shell_TrayWnd',nil),0,
'TrayNotifyWnd',nil);
p1 := POINTER(GetWindowLong(wnd,0));
if(p1 <> nil) then
begin
GetWindowThreadProcessId(wnd,@pid);
ph := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
false,pid);
if(ph <> 0) then
try
try
ReadProcessMemory(ph,p1,@twi,sizeof(TTrayWindowInfo),c1);
ReadProcessMemory(ph,POINTER(twi.iconList),@
il,sizeof(
il),c1);
ReadProcessMemory(ph,twi.iconsInfo,@tisi,sizeof(TTrayIconsInfo),c1);
for i := 0 to tisi.IconCount - 1 do
begin
ReadProcessMemory(ph,tisi.trayIconInfos^[i],
@tii,sizeof(TTrayIconInfo),c1);
if(Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
begin
tii.notifyIconDataA.cbSize := sizeof(TNotifyIconDataA);
tip := tii.notifyIconDataA.szTip;
end
else
begin
tii.notifyIconDataW.cbSize := sizeof(TNotifyIconDataW);
tip := tii.notifyIconDataW.szTip;
end;
GetWindowThreadProcessId(tii.notifyIconDataA.wnd,
@pid);
// Icon holen
idx := -1;
ico := TIcon.Create;
try
ico.Handle := ImageList_ExtractIcon(0,
cardinal(@
il),tii.imageIndex);
idx := HTIMainForm.lvimg.AddIcon(ico);
finally
ico.Free;
end;
// Daten eintragen
with lv1 do
begin
Items.Add;
Items[Items.Count-1].Caption := tip;
Items[Items.Count-1].SubItems.Add(lowercase('$' +
inttohex(tii.notifyIconDataA.Wnd,8)));
Items[Items.Count-1].SubItems.Add(lowercase('$' +
inttohex(pid,8)));
Items[Items.Count-1].SubItems.Add(lowercase(
pathfinder(pid)));
Items[Items.Count-1].ImageIndex := idx;
end;
end;
except
end;
finally
CloseHandle(ph);
end;
end;
lv1.Items.EndUpdate;
end;