如何取得程序内嵌入的网页中的连接并模拟点击事件(网页跟系统高手)(300分)

  • 主题发起人 主题发起人 陈晨
  • 开始时间 开始时间

陈晨

Unregistered / Unconfirmed
GUEST, unregistred user!
<a href="event://command=40026" class="nav">发送文件</a>
这是一个网页的连接,此网页被嵌入一程序中如何模拟点击命令
 
1、先用EnumWindows等函数得到IE所有控件的Handle
2、向目标控件发送WM_LBUTTONDOWN模拟点击。
 
//特定窗口的特定位置按下鼠标左键
procedure TForm1.Button2Click(Sender: TObject);
var
Wnd: HWND;
WinPos: TRect;
xy: TPoint;
begin

Wnd := FindWindow('TAppBuilder',nil); //找到Delphi IDE 的 handle
if Wnd <> 0 then
begin
SetForegroundWindow(Wnd);
GetWindowRect(Wnd,WinPos);
xy.x := WinPos.Left + 10; //(10,10)是窗口内的相对位置。
xy.y := WinPos.Top + 10;
SetCursorPos(xy.x,xy.y);
Mouse_Event(MOUSEEVENTF_LEFTDown,xy.x,xy.y,0,0);
Mouse_Event(MOUSEEVENTF_LEFTUP, xy.x,xy.y,0,0);
end
else ShowMessage('window not found');

end;

好象有更高级的方法可以分析网页中内容并进行相应操作。
 
谢谢 zw84611 的回答,
我想了解的也是您说的分析网页中内容并进行相应操作
 
直接再IE里访问event://command=40026不就可以了?
 
如果用WebBrowser控件了则很简单
 
to:satanmonkey 我打算在自己的程序中实现

to:zygtp能不能详细点。webBrowser控件不是很会用
 
想知道。期待ing
 
前几天写的一个游戏帐号自动申请程序.(现在的游戏帐号很多是通过网页申请的)
希望对你有帮助.:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, sendword,
Dialogs, StdCtrls, OleCtrls, SHDocVw, mshtml, ActiveX, Buttons, ExtCtrls;

type
TForm1 = class(TForm)
WB1: TWebBrowser;
BitBtn1: TBitBtn;
Panel1: TPanel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure WB1DownloadComplete(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
appPath: string;
end;

var
Form1: TForm1;
firstrun: Boolean;

implementation

{$R *.dfm}

procedure delays(Delay_Time: Integer);
var
FirstTickCount: real;
begin
FirstTickCount := GetTickCount;
repeat
Application.ProcessMessages;
until ((GetTickCount - FirstTickCount) >= Delay_Time); //delay time
Application.ProcessMessages;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if WB1.Document <> nil then
IHTMLWindow2(WB1.Document).focus
end;

procedure TForm1.FormShow(Sender: TObject);
begin

WB1.Navigate('file:///E:/csw/gametools/regaccount/newreg.htm');
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
I: Integer;
str: string;
begin
firstrun := False;
if WB1.Document <> nil then
begin
with (WB1.Application as IOleobject) do
DoVerb(OLEIVERB_UIACTIVATE, nil, WB1, 0, Handle, GetClientRect);
//生成用户名
Randomize;
for I := 1 to 7 do
begin
str := str + Inttostr(Random(GetTickCount));
end;
str := Copy(str, 2, 7);
SendKeys('a');
for i := 1 to length(str) do
SendKeys(copy(str, i, 1)); //user name
Application.ProcessMessages;
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), 0, 0);
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), keyeventf_keyup, 0);
application.ProcessMessages;
for i := 1 to length(str) do
SendKeys(copy(str, i, 1)); //first password
Application.ProcessMessages;
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), 0, 0);
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), keyeventf_keyup, 0);
Application.ProcessMessages;
for i := 1 to length(str) do // confirm password
SendKeys(copy(str, i, 1));
Application.ProcessMessages;
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), 0, 0); //jump to regiter button
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), keyeventf_keyup, 0);
Application.ProcessMessages;
keybd_event(VK_Space, mapvirtualkey(VK_Space, 0), 0, 0); //push space key
keybd_event(VK_Space, mapvirtualkey(VK_Space, 0), keyeventf_keyup, 0);
Application.ProcessMessages;
Edit1.Text:=str;
delays(500);
WB1.Navigate('file:///E:/csw/gametools/regaccount/newreg.htm');
WB1.SetFocus;
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), 0, 0);
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), keyeventf_keyup, 0);
end;
end;

procedure TForm1.WB1DownloadComplete(Sender: TObject);
begin
if firstrun then
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), 0, 0);
keybd_event(vk_tab, mapvirtualkey(vk_tab, 0), keyeventf_keyup, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
DetailHtml: TStrings;
begin
firstrun := True;
appPath := ExtractFilePath(application.ExeName);
DetailHtml := TStringList.Create;
try
DetailHtml.Add('');


finally
DetailHtml.Free;
end;
end;

end.

 
//这是我通过网页连接调用动态库的例子,若是url则用WebBrowser1.Navigate(url);即可
rocedure TForm_Main.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
sDll_Name,sFun_Name,sTemp:String;
begin
if PCommon.AnalyzeUrl(URL,sDll_Name,sFun_Name)=true then
begin
Cancel:=true;
PCommon.RunDll(sDll_Name,sFun_Name);
end

end;
 
后退
顶部