外挂程序的处理!!!
先找到主程序的HANDLE
procedure TForm2.Button1Click(Sender: TObject);
var
fwnd: Integer;
i_HWND :Integer;
i_HWND_child :Integer;
i_len:Integer;
s :string;
s1 :string;
is_success :boolean;
begin
fwnd:=FindWindow('TMemo','Form2');
if (fwnd=0) then
begin
memo1.Lines.Add('错误! 没有发现消息窗口');
exit ;
end
else
memo1.Lines.Add('找到消息窗口 句柄是'+inttostr(fwnd));
i_HWND:= GetWindow(fwnd,GW_Child);
postmessage( i_HWND ,WM_CLOSE,0,0);
postmessage( i_HWND ,WM_DESTROY,0,0);
while (true) do
begin
i_HWND_child:= GetNextWindow( i_HWND, GW_HWNDNEXT );
if(i_HWND_child=0 ) then
break;
i_HWND :=i_HWND_child;
end;
i_HWND:= GetWindow(i_HWND,GW_Child);
i_HWND:= GetWindow(i_HWND,GW_Child);
SetLength (s, 100);
while (true) do
begin
i_HWND_child:= GetNextWindow( i_HWND, GW_HWNDNEXT );
if(i_HWND_child=0 ) then
break;
i_HWND :=i_HWND_child;
i_len :=GetWindowTextLength(i_HWND);
GetWindowText(i_HWND, PChar(s), i_len);
setstring(s1, PChar(s),8) ;
if(s1 ='发送(&S)') then
break;
end;
memo1.Lines.Add('找到控件句柄:' +inttostr(i_HWND));
//is_success:= postmessage( i_rich ,WM_KEYDOWN,83,i);
is_success:= postmessage( i_HWND ,WM_CLOSE,0,0);
if (is_success) then
memo1.Lines.Add('成功')
else
memo1.Lines.Add('失败');
end;
摘自程序的某一段,读者自己测试。
浙公网安备 33010602011771号