5,390
社区成员
发帖
与我相关
我的任务
分享
function CallBackProc(H, HMainForm: hwnd): Boolean; stdcall;
var
hChild : hwnd;
begin
Result := True;
if GetParent(H) = HMainForm then begin //可以在这里进一步判断类名,以免关掉其他弹出窗口
hChild := FindWindowEx(H, 0, PChar('Button'), PChar('确定'));
if hChild > 0 then SendMessage(hChild, BM_Click, 0, 0);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
EnumWindows(@CallBackProc, Self.Handle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.WebBrowser1.Navigate('C:\Documents and Settings\jiaotongju\桌面\test2\test.htm');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.Timer1.Enabled := True;//Web页面装载完毕后开启Timer
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Self.Timer1.Enabled := False;
Self.Timer1.Interval:= 100;
end;
'这是C:\Documents and Settings\jiaotongju\桌面\test2\test.htm的内容
<html>
<head>
<title>test</title>
</head>
<body>
<form method="POST" action="">
<p><input type="button" value="按钮" name="B1" onclick="alert('关掉我')"></p>
</form>
</body>
</html>
function CallBackProc(H, HMainForm: hwnd): Boolean; stdcall;
var
hChild : hwnd;
begin
Result := True;
if GetParent(H) = HMainForm then begin
hChild := FindWindowEx(H, 0, PChar('Button'), PChar('确定'));
if hChild > 0 then SendMessage(hChild, BM_Click, 0, 0);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
EnumWindows(@CallBackProc, Self.Handle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.WebBrowser1.Navigate('C:\Documents and Settings\jiaotongju\桌面\test2\test.htm');
Self.Timer1.Enabled := True;//这句只是我测试时放在了这里
end;