隐藏,显示其他程序的托盘图标
隐藏,显示其他程序的托盘图标(此为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