实际上是如何控制一个程序窗口
procedure TForm1.Button1Click(Sender: TObject);
var
h1,h:hwnd;
r:trect;
begin
h1:=shellexecute(handle,'open','g:\oicq\oicq.exe','','',sw_show);
repeat
h:=findwindow(nil,'OICQ用户登录');
sleep(20);
until h<>0;
sendmessage(h1,wm_paint,0,0);
GetWindowRect(h,r);
SetForegroundWindow(h);
setcursorpos(r.Left+210,r.Top+145);
Mouse_Event(MOUSEEVENTF_LEFTDOWN,r.Left+210,r.Top+145,0,0);
Mouse_Event(MOUSEEVENTF_LEFTUP,r.Left+210,r.Top+145,0,0);
end;
至于密码的问题,必须使用EnumChildWindow(),还要写回调函数,所以比较麻烦。
Top
回复人: Kingron(沉沦中……) ( ) 信誉:100 2001-3-25 18:35:00 得分:0
哎,看见分数很多,所以就帮你写了:
不过你自己应该区分一下,判断那个是否是一个密码框。
function Callback(h:hwnd;param:Lparam):boolean;stdcall;
var
buf:array[0..255] of char;
begin
result:=true;
GetClassName(h,@buf,255);
if strpas(buf)='Edit' then
begin
Enablewindow(h,true);
sendmessage(h,wm_settext,255,integer(pchar('Password')));
// result:=false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h1,h:hwnd;
r:trect;
begin
h1:=shellexecute(handle,'open','g:\oicq\oicq.exe','','',sw_show);
repeat
h:=findwindow(nil,'OICQ用户登录');
sleep(50);
until h<>0;
sendmessage(h1,wm_paint,0,0);
GetWindowRect(h,r);
SetForegroundWindow(h);
setcursorpos(r.Left+210,r.Top+145);
Mouse_Event(MOUSEEVENTF_LEFTDOWN,r.Left+210,r.Top+145,0,0);
Mouse_Event(MOUSEEVENTF_LEFTUP,r.Left+210,r.Top+145,0,0);
sleep(1000);
h:=Findwindow(nil,'OICQ 注册向导');
EnumChildWindows(h,@CallBack,0);
caption:=SysErrorMessage(getlasterror);
end;