2010-02-04 64 views

回答

1

这里是我的方法与Windows XP和Delphi 2010,如果您使用的是版本的Delphi至极的不支持Unicode化妆舒尔你转换读ANSI

uses CommCtrl; 

function TForm1.GetIconsCount: Integer; 
begin 
    Result := SendMessage(FindTrayToolbar, TB_BUTTONCOUNT, 0, 0); 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    ListTips; 
end; 

function TForm1.FindTrayToolbar: HWND; 
begin 
    Result := FindWindow('Shell_TrayWND', nil); 
    Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil); 
    Result := FindWindowEx(Result, 0, 'SysPager', nil); 
    Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil); 
end; 

procedure TForm1.ListTips; 
var 
    dwTray: DWORD; 
    wndTray: HWND; 
    hTray: THandle; 
    remoteTray: Pointer; 
    tdata: TTBBUTTON; 
    i: Integer; 
    btsread:DWORD; 
    str:Pchar; 
begin 
    wndTray := FindTrayToolbar; 
    GetWindowThreadProcessId(wndTray, @dwTray); 
    hTray := OpenProcess(PROCESS_ALL_ACCESS, false, dwTray); 
    if hTray <> 0 then 
    begin 
    remoteTray := VirtualAllocEx(hTray, nil, Sizeof(tdata), MEM_COMMIT, 
     PAGE_READWRITE); 
    for i := 0 to GetIconsCount - 1 do 
    begin 
     SendMessage(FindTrayToolbar,TB_GETBUTTON,wparam(i),lparam(remotetray)); 
     ReadProcessMemory(hTray,remotetray,@tdata,sizeof(tdata),btsread); 
     GetMem(str,255); 
     ReadProcessMemory(hTray,Ptr(tdata.iString),str,255,btsread); 
     ListBox1.Items.Add(str); 
     end; 
     end 
     else ShowMessage('Could not locate tray icons'); 
    end; 
    end. 
4

该shell不提供检查不属于您的程序的通知图标的功能。 (而且它没有提供列举甚至属于你的程序的图标的方式,你将会比已经知道这些。)

我用的是被劫持的部分或全部的图标的程序和可选地将它们显示在它自己的窗口中而不是在时钟附近的区域中,所以它一定能够获得所有图标的列表。 Mike Lin,是TraySaver。如果你想看看他的黑客是如何工作的,可以使用源代码。

你也可以看看前面提到的关于controlling the position of icons in the notification area的问题的答案。

+0

我可以列举的图标中的字符串测试系统托盘 我可以枚举应用程序(handle,pid,path) 我可以控制图标的位置。 但我不能得到工具提示。那就是我想知道的。 –

+0

你可能会提到在这个问题中:“我可以枚举这些图标,但是我无法获得工具提示,下面是我正在使用的代码,请帮助填写空白。你读过我给你的第二个链接了吗? –

+0

是的,我读了第二个链接。 我可以控制通知区域中的图标。但那是另一回事。 或多或少使用相同的代码,我可以枚举系统托盘中的图标。 (从http://www.codeproject.com/KB/applications/ShellTrayInfo.aspx翻译) 但我不能得到他们的工具提示。 –

2

你应该看看madshis组件集合的madKernal package。它有一些working with trayicons的接口。但请注意:

使用madKernel,您可以管理任何应用程序的托盘图标(请参阅API“Shell_NotifyIcon”)。这种功能完全没有记录,但从win95到winXP运行良好。

ITrayIcon接口具有提示,图标,位置等属性。

相关问题