隐藏,显示其他程序的托盘图标

发布时间:2011年1月2日 作者:未知 查看次数:1779

隐藏,显示其他程序的托盘图标


隐藏,显示其他程序的托盘图标(此为Delphi代码)

Delphi

USES Commctrl,ShellAPI

procedure TForm1.Button1Click(Sender: TObject);
var TBHWND:HWND;
    i,count:integer;
    PID,PRC: THandle;
    Buff: PChar;
    Info: _TBBUTTON;
    R: Cardinal;
    S: array[0..1024] of char;
begin
TBHWND := FindWindow('Shell_TrayWnd', nil);                  // Shell_TrayWnd: 任务栏窗口
TBHWND := FindWindowEx(TBHWND, 0, 'TrayNotifyWnd', nil);     // TrayNotifyWnd:任务栏类
TBHWND := FindWindowEx(TBHWND, 0, 'ToolbarWindow32', nil);   // ToolbarWindow32托盘类,是一个toolbar//  wd:=FindWindowEx(wd,0,'SysPager',NIL);


if TBHWND=0 then exit;

GetWindowThreadProcessId(TBHWND, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);

count:=SendMessage(TBHWND,TB_BUTTONCOUNT,0 0);          //托盘中button的个数,不一定是图标的个数,有些button是隐藏的。

for i:=0 to count-1 do
    begin
      FillChar(Info, SizeOf(Info), 0);
      WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R);  //消息使用的内存空间必须在Shell之内,所以利用ReadProcessMemoery和WriteProcessMemory。


      SendMessage(TBHWND, TB_GETBUTTON, i, integer(Buff));
      ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R);

      SendMessage(TBHWND, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) SizeOf(Info)));
      ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) SizeOf(Info)), @S[0], SizeOf(S), R);

      if pos('QQ',StrPas(S))>0 then            //如果button的TEXT中包含'QQ'
         SendMessage(TBHWND, TB_DELETEBUTTON, i, 0);          //删除
      Form1.Memo1.Lines.Add(StrPas(S));        //在MEMO1中记录所有button的TEXT
    end;


VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;

相关的消息:
TCM_ADJUSTRECT       TB_ADDBITMAP
TCM_DELETEALLITEM    TB_ADDBUTTONS           TB_GETMAXSIZE               TB_SAVERESTORE
TCM_DELETEITEM       TB_ADDSTRING            TB_GETOBJECT                TB_SETANCHORHIGHLIGHT
TCM_DESELECTALL      TB_AUTOSIZE             TB_GETPADDING               TB_SETBITMAPSIZE
TCM_GETCURFOCUS      TB_BUTTONCOUNT          TB_GETRECT                  TB_SETBUTTONINFO
TCM_GETCURSEL        TB_BUTTONSTRUCTSIZE     TB_GETROWS                  TB_SETBUTTONSIZE
TCM_GETEXTENDEDSTYLE TB_CHANGEBITMAP         TB_GETSTATE                 TB_SETBUTTONWIDTH
TCM_GETIMAGELIST     TB_CHECKBUTTON          TB_GETSTYLE                 TB_SETCMDID
TCM_GETITEM          TB_COMMANDTOINDEX       TB_GETTEXTROWS              TB_SETDISABLEDIMAGELIST
TCM_GETITEMCOUNT     TB_CUSTOMIZE            TB_GETTOOLTIPS              TB_SETEXTENDEDSTYLE
TCM_GETITEMRECT      TB_DELETEBUTTON         TB_HIDEBUTTON               TB_SETHOTIMAGELIST
TCM_GETROWCOUNT      TB_ENABLEBUTTON         TB_HITTEST                  TB_SETHOTITEM
TCM_GETTOOLTIPS      TB_GETANCHORHIGHLIGHT   TB_INDETERMINATE            TB_SETIMAGELIST
TCM_HIGHLISHTITEM    TB_GETBITMAP            TB_INSERTBUTTON             TB_SETINDENT
TCM_HITTEST          TB_GETBITMAPFLAGS       TB_INSERTMARKHITTEST        TB_SETINSERTMARK
TCM_INSERTITEM       TB_GETBUTTON            TB_ISBUTTONCHECKED          TB_SETINSERTMARKCOLOR
TCM_REMOVEIMAGE      TB_GETBUTTONINFO        TB_ISBUTTONENABLED          TB_SETMAXTEXTROWS
TCM_SETCURFOCUS      TB_GETBUTTONSIZE        TB_ISBUTTONHIDDEN           TB_SETPADDING
TCM_SETCURSEL        TB_GETBUTTONTEXT        TB_ISBUTTONHIGHLIGHTED      TB_SETPARENT
TCM_SETEXTENDEDSTYLE TB_GETDISABLEDIMAGELIST TB_ISBUTTONINDETERMINATE    TB_SETROWS
TCM_SETIMAGELIST     TB_GETEXTENDEDSTYLE     TB_ISBUTTONPRESSED          TB_SETSTATE
TCM_SETITEM          TB_GETHOTIMAGELIST      TB_LOADIMAGES               TB_SETSTYLE
TCM_SETITEMEXTRA     TB_GETHOTITEM           TB_MAPACCELERATOR           TB_SETTOOLTIPS
TCM_SETITEMSIZE      TB_GETIMAGELIST         TB_MARKBUTTON
TCM_SETMINTABWIDTH   TB_GETINSERTMARK        TB_MOVEBUTTON
TCM_SETPADDING       TB_GETINSERTMARKCOLOR   TB_PRESSBUTTON
TCM_SETTOOLTIPS      TB_GETITEMRECT          TB_REPLACEBITMAP

 



版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110