【问题标题】:How can I get the tooltips of notification-area icons?如何获取通知区域图标的工具提示?
【发布时间】:2010-02-04 23:16:19
【问题描述】:

我可以在通知区域用图标枚举应用程序(handle,pid,path),并且可以控制图标的位置,但是我无法获取工具提示。

如何枚举系统托盘图标,包括工具提示?

【问题讨论】:

    标签: delphi delphi-2007 notification-area


    【解决方案1】:

    shell 不提供检查不属于您的程序的通知图标的功能。 (而且它甚至无法列举 属于您的程序的图标;您应该已经知道这些。)

    我曾经使用一个程序劫持了部分或全部图标,并有选择地将它们显示在自己的窗口中,而不是在时钟附近的区域中,因此它一定能够获取所有图标的列表。是TraySaver,作者是 Mike Lin。如果您想了解他的 hack 是如何工作的,可以使用源代码。

    您还可以查看上一个关于controlling the position of icons in the notification area 的问题的答案。

    【讨论】:

    • 我可以枚举系统托盘中的图标 我可以枚举应用程序(句柄、pid、路径) 我可以控制图标的位置。但我无法获得工具提示。这就是我想知道的。
    • 您可以在问题中提到这一点:“我可以枚举图标,但无法获取工具提示。这是我正在使用的代码。请帮助填写空白。”你读过我给你的第二个链接吗?
    • 是的,我阅读了第二个链接。我可以控制通知区域中的图标。但那是另一个故事。或多或少使用相同的代码,我可以枚举系统托盘中的图标。 (来自codeproject.com/KB/applications/ShellTrayInfo.aspx 的翻译)但我无法获得他们的工具提示。
    【解决方案2】:

    你应该看看 madshis 组件集合的madKernal package。它有一些working with trayicons 的接口。不过要小心:

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

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

    【讨论】:

      【解决方案3】:

      这是我在 windows xp 和 delphi 2010 上测试的方法,如果您使用的是不支持 unicode 的 delphi 版本,请确保您将读取的字符串转换为 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.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-25
        • 2018-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多