一外部程序运行时,我可以获得该程序主窗体的句柄,该程序还有一个托盘图标,如何才能获得该托盘图标的Hint,并在另外一个程序中显示出来。 
    如果上述问题不能解决,可不可以将右下角所有托盘图标的Hint一起读出来,而不需要管哪个托盘图标是哪个应用程序的。     据我所知,一下代码可以获得任务栏时钟的Text。 var 
    Wnd:   THandle; 
begin
 Wnd:=FindWindow(′Shell_TrayWnd′,nil); 
 Wnd:=FindWindowEx(Wnd,HWND(0),′TrayNotifyWnd′,nil); 
 Wnd:=FindWindowEx(Wnd,HWND(0),′TrayCLockWClass′,nil); 
end;

解决方案 »

  1.   

    既然能找到Shell_TrayWnd的句柄,应该可以枚举其所有的子窗体吧
      

  2.   

    很早以前写的一段代码,枚举托盘图标  TTBBinfo = record
        ttbb: TTBButton;
        ttbbi: TBBUTTONINFO;
        Text: array[0..256-1] of Char;
        Icon: HICON;
        bValid: boolean;
        bVisible: BOOL;
        bmp: TBitmap;
      end;function GetTrayButtons():Integer;
    var
      i,nCount: Integer;
      Buffer: PChar;
      PID: THandle;
      hPRC: THandle;
      dwRead: Cardinal;
      ImageList: HIMAGELIST;
    begin
      Result:=0;
      GetWindowThreadProcessId(hToolBar, @PID);
      hPRC:= OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
      Buffer:= VirtualAllocEx(hPRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
      try    //FreeTTBBS;
        nCount:= SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
        SetLength(ttbbs,nCount);    for i:=0 to nCount-1 do
        begin
          FillChar(ttbbs[i].ttbb, SizeOf(ttbbs[i].ttbb),0);
          WriteProcessMemory(hPRC, Buffer, @(ttbbs[i].ttbb), SizeOf(ttbbs[i].ttbb),dwRead);      SendMessage(hToolBar, TB_GETBUTTON, i, Integer(Buffer));
          ReadProcessMemory(hPRC, Buffer, @(ttbbs[i].ttbb), SizeOf(ttbbs[i].ttbb), dwRead);      SendMessage(hToolBar, TB_GETBUTTONINFO, ttbbs[i].ttbb.idCommand, Integer(Integer(@Buffer[0]) + SizeOf(ttbbs[i].ttbb)));
          ReadProcessMemory(hPRC, Pointer(Integer(@Buffer[0]) + SizeOf(ttbbs[i].ttbb)), @(ttbbs[i].ttbbi), SizeOf(ttbbs[i].ttbbi), dwRead);      SendMessage(hToolBar, TB_GETBUTTONTEXT, ttbbs[i].ttbb.idCommand, Integer(Integer(@Buffer[0]) + SizeOf(ttbbs[i].ttbb)+ Sizeof(ttbbs[i].ttbbi)));
          ReadProcessMemory(hPRC, Pointer(Integer(@Buffer[0]) + SizeOf(ttbbs[i].ttbb)+ Sizeof(ttbbs[i].ttbbi)), @(ttbbs[i].Text[0]), SizeOf(ttbbs[i].Text), dwRead);      if Trim(ttbbs[i].Text)='' then
            ttbbs[i].Text:='[NONAME]';      ImageList:= SendMessage(hToolbar, TB_GETIMAGELIST, 0, 0);
          ttbbs[i].Icon:=ImageList_GetIcon(ImageList,ttbbs[i].ttbb.iBitmap,ILD_NORMAL);
          ttbbs[i].bValid:=ttbbs[i].ttbb.iString<>-1;
          ttbbs[i].bVisible:=not BOOL(SendMessage(hToolBar, TB_ISBUTTONHIDDEN, ttbbs[i].ttbb.idCommand, 0));
        end;
      finally
        VirtualFreeEx(hPRC, Buffer, 0, MEM_RELEASE);
        CloseHandle(hPRC);
        Result:=nCount;
      end;
    end;