隐藏托盘图标的问题
程序运行后未能实现隐藏功能,请大家帮忙看看问题出在哪,在下新手,谢谢!!!
unit tray;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
//procedure FormCreate(Sender: TObject);
procedure enumTrayNotifyWnd;
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Commctrl;
procedure TForm1.enumTrayNotifyWnd;
var
wd:HWND;
wtd:HWND;
wd1:HWND;
pid:DWORD;
hd:THandle;
num,i:integer;
n:ULONG;
x:string;
name :array[0..255] of WCHAR;
whd,proid :ulong;
temp :string;
sp:^TTBBUTTON;
_sp:TTBBUTTON;//结构体
pp:^TTBBUTTON;
p:TTBBUTTON;
begin
wd:=FindWindow('Shell_TrayWnd',nil); //寻找父窗口
if (wd=0) then
begin
showmessage('Error1');
exit;
end;
wtd:=FindWindowEx(wd,0,'TrayNotifyWnd',nil); //右下角任务栏
if (wtd=0) then
begin
showmessage('Error2');
exit;
end;
wtd:=FindWindowEx(wtd,0,'SysPager',nil); //主要显示栏
if (wtd=0) then
begin
showmessage('SysPager');
exit;
end;
wd1:=FindWindowEx(wtd,0,'ToolbarWindow32',nil);//图标区
if (wd1=0) then
begin
showmessage('Error3');
exit;
end;
pid:=0;
GetWindowThreadProcessId(wd1,@pid);//返回进程 ID 的指针
if (pid=0) then
begin
showmessage('Error4');
exit;
end;
hd:=OpenProcess(PROCESS_ALL_ACCESS ,true,pid);//返回进程的句柄
if (hd=0) then
begin
showmessage('Error6'#13+ IntToStr(hd));
exit;
end;
num:=SendMessage(wd1,TB_BUTTONCOUNT,0,0);//获取图标个数
sp:=@_sp;//sp是指针
for i:= 0 to num do
begin
SendMessage(wd1,TB_GETBUTTON,i,integer(sp));//integer强制类型转换
pp:=@p;
ReadProcessMemory(hd,sp,pp,sizeof(p),n);
//x:=Format('%x %x %x %x %x %x ',[p.iBitmap,p.idCommand,p.fsState,p.fsStyle,p.dwData,p.iString]);
name[0]:=char(0);
if (Cardinal(p.iString) <>$ffffffff) then
begin
try
ReadProcessMemory(hd,pointer(p.iString),@name,255,n);
name[n]:=char(0);
except
showmessage('except1')
end;
temp:=name;
try
whd:=0;
ReadProcessMemory(hd,pointer(p.dwData),@whd,4,n);
except
end;
proid:=0;
GetWindowThreadProcessId(whd,@proid);
x:=x+#13+Format('位置=%d 名称=%s 窗口句柄=%x 进程ID=%x',[i,temp,whd,proid]);
end;
end;
ShowMessage(x);
end;
end.