SendMessage(wd1,TB_GETBUTTON,i,integer(sp));也有错 ( 积分: 100 )

  • 主题发起人 主题发起人 pangzhenguang
  • 开始时间 开始时间
P

pangzhenguang

Unregistered / Unconfirmed
GUEST, unregistred user!
SendMessage(wd1,TB_GETBUTTON,i,integer(sp));也有错,大家麻烦帮我看一下
有时错,有时没错
function enumTrayNotifyWnd:String;
var
wd:HWND;
wtd:HWND;
wd1:HWND;
pid:DWORD;
hd:THandle;
num,i:integer;
n:ULONG;
p:TTBBUTTON;
pp:^TTBBUTTON;
x:string;
name :array[0..255] of WCHAR;
whd,proid :ulong;
temp :string;
sp:^TTBBUTTON;
_sp:TTBButton;

lStr:String;
lpos:integer;
begin
Result :='';
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);
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;
for i:= 0 to num-1 do
begin
SendMessage(wd1,TB_GETBUTTON,i,integer(sp));

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;
 
usesCommctrl
 
XP系统 下也有错,有时在2000系统下可以,有时不行,不知是什么原因
 
用longint(sp)会不会好点
 
一没错就一直没错,,直到关机一有错就一直有错,直到关机,
 

Similar threads

I
回复
0
查看
774
import
I
I
回复
0
查看
631
import
I
I
回复
0
查看
600
import
I
I
回复
0
查看
783
import
I
后退
顶部