问题很简单,翻译个20行C++代码为delhi程序(50分)

  • 主题发起人 主题发起人 52253831
  • 开始时间 开始时间
5

52253831

Unregistered / Unconfirmed
GUEST, unregistred user!
C++实在是高深莫测,我是没法学了。
啥也别说了,翻译下一成为delphi语言
int main()
{
HWND wd=::FindWindow("Shell_TrayWnd",NULL);
if (wd==NULL)
{
// MessageBox("Error1");
return 0;
}
HWND wtd=FindWindowEx(wd,NULL,"TrayNotifyWnd",NULL);
if (wtd==NULL)
{
// MessageBox("Error2");
return 0;
}
HWND hdt=FindWindowEx(wtd,NULL,"SysPager",NULL);
if(hdt==NULL)
{
// MessageBox("Errortttt");
return 0;
}
HWND wd1=FindWindowEx(hdt,NULL,"ToolbarWindow32",NULL);
if (wd1==NULL)
{
// MessageBox("Error3");
return 0;
}
DWORD pid;
pid=0;
GetWindowThreadProcessId(wd1,&pid);
if (pid==NULL)
{
// MessageBox("Error4");
return 0;
}

HANDLE hd=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_ALL_ACCESS,true,pid);
if (hd==NULL)
{
// MessageBox("Error6");
return 0;
}

int num=::SendMessage(wd1,TB_BUTTONCOUNT ,NULL,NULL);
int i;
unsigned long n;
TBBUTTON p,*pp;
CString x;
wchar_t name[256];
unsigned long whd,proid;
CString temp;

TBBUTTON *sp;

sp= (TBBUTTON *)0x20f00;
for(i=0;i<num;i++)
{
::SendMessage(wd1,TB_GETBUTTON,i,(LPARAM)sp);
pp=&p;
ReadProcessMemory(hd,sp,pp,sizeof(p),&n);
name[0]=0;
if (p.iString!=0xffffffff)
{
try
{
ReadProcessMemory(hd,(void *)p.iString,name,255,&n);
name[n]=0;
}
catch(...)
{}
}

temp=name;
try
{
whd=0;
ReadProcessMemory(hd,(void *)p.dwData,&whd,4,&n);
}
catch(...)
{}
proid=0;
GetWindowThreadProcessId((HWND)whd,&proid);
x.Format("位置=%d 名称=%s 窗口句柄=%08x 进程ID=%08x /n",i,(LPCTSTR )temp,whd,proid);
cout <<x;

}
return 0;
}
 
在线啊等啊,
 
看看下面行不行
procedure TForm1.Button1Click(Sender: TObject);
var
wd,wtd,hdt,wd1,pid,hd:thandle;
num:integer;
i:Integer;
n,whd,proid:longword;
p:ttbbutton;
sp,pp:^ttbbutton;
x,temp:string;
p1:pointer;
name:array[0..255] of char;
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;
hdt:=findwindowex(wtd,0,'syspager',nil);
if hdt<=0 then
begin
showmessage('errortttt');
exit;
end;
wd1:=findwindowex(hdt,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_query_information or process_all_access,true,pid);
if hd=0 then
begin
showmessage('error6');
exit;
end;
num:=sendmessage(wd1,TB_BUTTONCOUNT ,0,0);
longword(p1):=$20f00;
sp:=p1;
for i:=0 to num-1 do
begin
sendmessage(wd1,tb_getbutton,i,lparam(sp));
pp:=@p;
readprocessmemory(hd,sp,pp,sizeof(p),n);
name[0]:=#0;
if p.iString <>$ffffffff then
begin
try
readprocessmemory(hd,@p.istring, @name[0],255,n);
name[n]:=#0;
except
//.....
end;
end;
temp:=name;
try
whd:=0;
ReadProcessMemory(hd,@p.dwData,@whd,4,n);
except
//...
end;
proid:=0;
getwindowthreadprocessid(whd,@proid);
format('位置=%d 名称=%s 窗口句柄=%08x 进程id=%08x',[i,temp,whd,proid]);
//输出x的值
end;
exit;
end;
 
不对啊,format('位置=%d 名称=%s 窗口句柄=%08x 进程id=%08x',[i,temp,whd,proid]);
和C++的值不同。不能名称,句柄,进程ID都是错的,
但C++是正确的。

再等解决。
 
搞好了,
 
后退
顶部