200 求代码,清除其它软件在托盘区的图标(200分)

  • 主题发起人 主题发起人 qi_jianzhou
  • 开始时间 开始时间
Q

qi_jianzhou

Unregistered / Unconfirmed
GUEST, unregistred user!
在不关闭其它程序的情况下,清除它在托盘区的图标,比如说电驴,BT,FlashGet 等

代码 100 分,思路注释 100 分

看了看以前的贴子,没有找到解决的办法,请高手帮忙
 
通过查找托盘区的图标(或者窗口)获得句柄,再获取其相关数据用
Shell_NotifyIcon(NIM_DELETE,@IconData);
删除图标
 
我能通过 窗体的 handle 来得到该窗体的托盘图标吗?
兄弟再说详细点
 
大侠们去哪了?来帮帮忙呀
 
删除自己的,或者删除其他已经关闭的程序还可以吧

你这种需求,我也想知道怎么能实现
 
能实现吗?怀疑!
 
应该能实现的
 
真这么难吗?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,commctrl,ShellAPI, CheckLst;

type
TForm1 = class(TForm)
Button1: TButton;
CheckListBox1: TCheckListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
id:array[0..30] of integer;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
v_hShellTray: THandle;
v_hTrayNotify: THandle;
v_hToolBar: THandle;
i,j,k:integer;
Info: _TBBUTTON;
buffer:pchar;
PID: THandle;
PRC: THandle;
R: Cardinal;
S:array[0..1024] of char;
MaxWidth: integer;
begin
k:=0;
CheckListBox1.Items.Clear;
v_hShellTray := FindWindow('Shell_TrayWnd', nil);
v_hTrayNotify := FindWindowEx(v_hShellTray, 0, 'TrayNotifyWnd', nil);
v_hToolBar := FindWindowEx(v_hTrayNotify, 0, 'ToolbarWindow32', nil);

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

j:=SendMessage(v_hToolBar,TB_BUTTONCOUNT,0,0);
for i:=0 to j-1 do
begin
FillChar(Info, SizeOf(Info), 0);
WriteProcessMemory(PRC, Buffer, @Info, SizeOf(Info), R);

SendMessage(v_hToolBar, TB_GETBUTTON, i, integer(Buffer));
ReadProcessMemory(PRC, Buffer, @Info, SizeOf(Info), R);
if Info.iString<>-1 then
begin
k:=k+1;
if not Boolean(SendMessage(v_hToolBar, TB_ISBUTTONHIDDEN, Info.idCommand, 0)) then
begin
SendMessage(v_hToolBar, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buffer[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buffer[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);
id[k-1]:= Info.idCommand;
CheckListBox1.Items.Add(S);
CheckListBox1.Checked[k-1]:=false;
end
else
begin
SendMessage(v_hToolBar, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buffer[0]) + SizeOf(Info)));
ReadProcessMemory(PRC, Pointer(integer(@Buffer[0]) + SizeOf(Info)), @S[0], SizeOf(S), R);
id[k-1]:= Info.idCommand;
CheckListBox1.Items.Add(S);
CheckListBox1.Checked[k-1]:=true;
end;
end;
end;
VirtualFreeEx(PRC, Buffer, 0, MEM_RELEASE);
CloseHandle(PRC);

MaxWidth := 0;
for i := 0 to CheckListBox1.Items.Count - 1 do
if MaxWidth < CheckListBox1.Canvas.TextWidth(CheckListBox1.Items.Strings) then
MaxWidth := CheckListBox1.Canvas.TextWidth(CheckListBox1.Items.Strings);
SendMessage(CheckListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+40, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
v_hShellTray: THandle;
v_hTrayNotify: THandle;
v_hToolBar: THandle;
lpData:PNotifyIconData;
begin
v_hShellTray := FindWindow('Shell_TrayWnd', nil);
v_hTrayNotify := FindWindowEx(v_hShellTray, 0, 'TrayNotifyWnd', nil);
v_hToolBar := FindWindowEx(v_hTrayNotify, 0, 'ToolbarWindow32', nil);
for i:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked=true then
begin
SendMessage(v_hToolBar, TB_HIDEBUTTON, id, integer(true));
end
else
begin
SendMessage(v_hToolBar, TB_HIDEBUTTON, id, integer(false));
end;
end;
//向任务栏添加一个图标后马上删除,使任务栏刷新。
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := 0;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);


end;

end.

自己写的程序,可以实现隐藏任务图标。
但还是我还想获得任务栏上的图标,不知道那位大虾能帮忙解决这个问题?
 
楼上兄弟,给点注释出来呀,我水平有限,有的看不明白
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
458
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部