unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var h1,h2,h21,h3,hdl:HWND;
begin
//启动窗口最小化
Form1.windowstate:=wsMinimized;
//自动登录txt
WinExec('C:\Program Files\Tencent\RTXC\RTX.exe',sw_maximize);
Sleep(1000); //等待1秒
//查找父窗口、子窗口、多控件句柄查找
h1:=FindWindow('#32770','窗口标题');
h2:=FindWindowex(h1,0,'#32770',nil);
h21:=getwindow(h2,GW_HWNDLAST);
h3:=FindWindowex(h21,0,'edit',nil);
//输入密码
sendmessage(h3,WM_SETTEXT,0,LongInt(Pchar('111111)));
//查找登录按钮句柄
hdl:=findwindowex(h21,0,'Button','登录');
//点击登录按钮登录
SendMessage(hdl,WM_LBUTTONDOWN,0,$000b0020);
SendMessage(hdl,WM_LBUTTONUP,0,$000b0020);
end;
end.