webbroswer 自动填表在Application.ShowMainForm := False;下无法运行

iakvl 2011-09-03 05:16:11
最近想设计一个程序隐藏登录网站
工程文件
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.ShowMainForm:=false;
Application.Run;
end.


var
o : Olevariant;
begin
o := WebBrowser.OleObject.document.all.item('LoginUserID',0); //找到登录用户名的输入框
o.value := 'TEST';
o := WebBrowser.oleobject.document.all.item('LoginPassword',0); //找到登录密码的输入框
o.value := 'TEST'
WebBrowser.oleobject.document.Forms.Item(0, 0).submit; //第一个表单提交
{
o :=WebBrowser.oleobject.document.all.item('Login',0); //或者用指定表单名称提交
o.Click; //点击操作,对其它对象也可同样操作
}
end;
使用以上代码实现自动填表,利用showmessage('')发现程序运行到 o:= WebBrowser.OleObject.document.all.item('LoginUserID',0); //找到登录用户名的输入框时就卡住了,cpu达到100%,内存无变化,
去掉Application.ShowMainForm:=false;这句,显示主窗口后一切正常,
是否在主窗口隐藏后无法使用WebBrowser.oleobject.document.all.item('Login',0)?
有没有好的解决方法?


...全文
91 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
iakvl 2011-09-06
  • 打赏
  • 举报
回复
总算找到了解决办法
procedure TForm1.FormCreate(Sender: TObject);
begin
Self.WebBrowser1.Navigate('WWW.SINA.COM');
Windows.SetParent(WebBrowser1.Handle, 1);
end;
unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, xpWindow, StdCtrls, AAFont, AACtrls; type TForm3 = class(TForm) Label2: TLabel; xpWindow1: TxpWindow; AAFadeText1: TAAFadeText; private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation {$R *.dfm} end. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, shellapi, Menus, StdCtrls, ExtCtrls, AAFont, AACtrls, AAFontDialog,Registry, xpWindow; const wm_traynotify=wm_user+1000; type TForm1 = class(TForm) PopupMenu1: TPopupMenu; NToDos: TMenuItem; NCancel: TMenuItem; NReboot: TMenuItem; NClose: TMenuItem; Memo1: TMemo; N1: TMenuItem; GroupBox1: TGroupBox; Timer1: TTimer; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; AAFontDialog1: TAAFontDialog; xpWindow1: TxpWindow; AAScrollText1: TAAScrollText; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure formdestroy(sender:tobject); procedure btnCancelClick(Sender: TObject); procedure btnToDosClick(Sender: TObject); procedure btnRebootClick(Sender: TObject); procedure btnCloseClick(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure CheckBox2Click(Sender: TObject); procedure CheckBox3Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure N1Click(Sender: TObject); private { Private declarations } my_tray_icon:tnotifyicondata; procedure wmmytrayiconcallback(var msg:tmessage); message wm_traynotify; public { Public declarations } // procedure GameGontrol(sender:TObject); end; var Form1: TForm1; game:array[0..255] of string; FilePath : string; implementation uses Unit2, Unit3; {$R *.DFM} // 自定义过程,用于程序运行后,屏蔽操作系统的任务管理器 procedure DisableTaskmgr(Key: Boolean); Var Reg:TRegistry; Begin Reg:=TRegistry.Create; try Reg.RootKey := HKEY_CURRENT_USER; if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\System', True) then begin if Key then Reg.WriteString('DisableTaskMgr','1') else Reg.WriteInteger('DisableTaskMgr',0); Reg.CloseKey; end; except Reg.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); var key:boolean; hKey:string; hReg:TregIniFile; registerTemp:TRegistry; begin // 程序开机自动运行 try registerTemp:=TRegistry.create; registerTemp.RootKey:=HKEY_LOCAL_MACHINE; if registerTemp.OpenKey('software\Microsoft\Windows\currentversion\run',True) then begin registerTemp.WriteString(extractfilename(application.ExeName),application.ExeName); end; except Showmessage('该程序无法自动运行,请及时与作者联系!'); end; disableTaskmgr(true); // 程序运行后,屏蔽系统任务管理器,防止学生强制关闭软件 visible:=false; application.ShowMainForm:=visible; with my_tray_icon do begin cbsize:=sizeof(tnotifyicondata); wnd:=handle; uid:=1; uflags:=nif_message or nif_icon or nif_tip; ucallbackmessage:=wm_traynotify; hicon:=loadicon(0,idi_winlogo); sztip:=''; end; shell_notifyicon(nim_add,@my_tray_icon); end; procedure tform1.formdestroy(sender:tobject); begin shell_notifyicon(nim_delete,@my_tray_icon); end; procedure tform1.wmmytrayiconcallback(var msg:tmessage); var cursorpos:tpoint; begin case msg.LParam of wm_lbuttondown: begin visible:=not visible; application.ShowMainForm:=visible; setforegroundwindow(application.handle); end; wm_rbuttondown: begin getcursorpos(cursorpos); popupmenu1.Popup(cursorpos.x,cursorpos.y); end; end; end; procedure TForm1.btnCancelClick(Sender: TObject); begin exitwindowsex(ewx_force,0); end; procedure TForm1.btnToDosClick(Sender: TObject); begin exitwindowsex(ewx_logoff,0); end; procedure TForm1.btnRebootClick(Sender: TObject); var st : SYSTEMTIME; hToken : THANDLE; tkp : TOKEN_PRIVILEGES; rr : Dword; begin OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken); LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid); // 设定权限为1 tkp.PrivilegeCount := 1; tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; // 得到权限 AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,rr); // 重起计算机 ExitWindowsEx(EWX_REBOOT , 0) end; procedure TForm1.btnCloseClick(Sender: TObject); begin // exitwindowsex(ewx_shutdown,0); Formclose.Show; end; procedure TForm1.CheckBox1Click(Sender: TObject); begin if checkbox1.Checked=true then begin checkbox2.Checked:=false; checkbox3.Checked:=false; end ; end; procedure TForm1.CheckBox2Click(Sender: TObject); begin if checkbox2.Checked=true then begin checkbox1.Checked:=false; checkbox3.Checked:=false; end; end; procedure TForm1.CheckBox3Click(Sender: TObject); begin if checkbox3.Checked=true then begin checkbox2.Checked:=false; checkbox1.Checked:=false; end; end; procedure TForm1.Timer1Timer(Sender: TObject); var hcurrentWindow:HWnd; szText:array[0..254] of char; Gamefile:TextFile; // 文本文件,存放已经知道的游戏句柄 s:string; // i,j:integer; st:SYSTEMTIME; hToken:THANDLE; tkp:TOKEN_PRIVILEGES; RR:Dword; begin try if form3.Showing=true then begin form3.Close; end; memo1.Clear; hCurrentWindow:=GetWindow(Handle,GW_HWNDFIRST); While hCurrentWindow<>0 do begin if GetWindowText(hCurrentWindow,@szText,255)>0 then Memo1.Lines.Add(strpas(@sztext)+Datetimetostr(now)); // for i:=0 to 254 do // begin try FilePath := ExtractFilePath(Application.ExeName); // 程序运行后,自动获取Game.txt的路径 assignfile(Gamefile,FilePath+'\game.txt'); // 准备读取game.txt中的信息 reset(Gamefile); except showmessage('^_^'); end; while not eof(Gamefile) do begin readln(Gamefile,s); if strPas(@szText)=s then begin form3.Show; // 发现游戏后,分别处理 if checkbox1.Checked=true then begin sendMessage(hCurrentWindow,WM_CLOSE,0,0); // 关闭游戏 end; if checkbox3.Checked=true then // 关闭计算机 begin openProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES OR TOKEN_QUERY,hToken); LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid); tkp.privilegecount:=1; tkp.privileges[0].Attributes:=se_privilege_enabled; adjusttokenprivileges(hToken,false,tkp,0,nil,rr); exitwindowsex(ewx_poweroff,0); end; if checkbox2.Checked=true then begin exitwindowsex(ewx_force,0); // 注销计算机 end; end; end; // end; hcurrentwindow:=getwindow( hCurrentWindow,gw_hwndnext); end; finally end; end; procedure TForm1.N1Click(Sender: TObject); var p:pchar; //指针,指向将被打开的帮助文件 begin p:=pchar(ExtractFilePath(Application.ExeName)+'Help.chm'); shellexecute(0,nil,p,nil,nil,SW_NORMAL); end; end. unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,registry,xpWindow; type TFormclose = class(TForm) GroupBox1: TGroupBox; Label1: TLabel; Edit1: TEdit; Button1: TButton; xpWindow1: TxpWindow; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Formclose: TFormclose; implementation uses Unit1; {$R *.dfm} // 自定义过程,用于程序运行后,屏蔽操作系统的任务管理器 procedure DisableTaskmgr(Key: Boolean); Var Reg:TRegistry; Begin Reg:=TRegistry.Create; try Reg.RootKey := HKEY_CURRENT_USER; if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\System', True) then begin if Key then Reg.WriteString('DisableTaskMgr','1') else Reg.WriteInteger('DisableTaskMgr',0); Reg.CloseKey; end; except Reg.Free; end; end; // 自定义过程,实现系统开机自动运行 procedure SetAuttorun(aProgTitle,aCmdLine:string;aRunOnce:boolean); var hKey:string; hReg:TRegIniFile; begin if aRunOnce then hKey:='Once' else hKey:=''; hReg:=TRegIniFile.Create(''); hReg.RootKey:=HKEY_LOCAL_MACHINE; hReg.WriteString('software\microsoft\windows\currentversion\run' +hKey+#0,aProgTitle,aCmdLine); // 修改操作系统注册表 hReg.Destroy; end; procedure TFormclose.Button1Click(Sender: TObject); var key:boolean; begin if edit1.Text='162534' then begin key:=false; DisableTaskmgr(key); // 当系统推出时恢复任务管理器 application.Terminate; end else begin showmessage('密码错误!'); formclose.Close; end; edit1.Clear; end; end.
DELPHI7下好用的托盘控件,安装简单,版本进度如下:TCoolTrayIcon, ver. 2.3.0 - ver. 2.3.0: Various minor bugs fixed: 1) Calling the ShowMainForm and HideMainForm methods before the main form was created would crash the app. Fixed thanks to James Legg. 2) The tooltip would give trouble if it was 64 chars. Thanks to Toms Baugis and Teus de Jong. 3) The popup menu would not close itself auto- matically if the StartMinimized property was true. Thanks to Ingo Krueger, Chris Witt, and Reister HansJoerg. - ver. 2.2.2: When there was more than one form visible the taskbar icon would not hide when the main form was minimized. Fixed. - ver. 2.2.1: Fixed a popup menu bug. Also fixed a bug which meant D2 and D3 users could not compile the component. Added more icon animations in the demo. Thanks to Daniele Gervasoni for the "tray graph". - ver. 2.2.0: IconIndex is now a property, allowing you to specify an icon at run-time. The OnCycle event is changed so it returns the index to the next icon that will display when cycling. Finally, I fixed a bug that caused the taskbar icon not to display itself when MinimizeToTray was true. Thanks to Lorenz Graf for pointing it out to me. - ver. 2.1.4: The main form will no longer show itself untimely after the form's BorderStyle property is changed. Thanks to Thomas Reimann. - ver. 2.1.3: Fixed a bug that caused the main form not to display itself (how embarassing). - ver. 2.1.2: I *finally* found the bug that would cause some compound controls (like controls on notebook pages or tab sheets) not to display properly when StartMinimized was true. Incidently, this also means that TForm.Position now works. Also fixed a minor bug that caused modal forms owned by the main form to appear behind the main form when the popup menu appeared (thanks to Arash Ramin). - ver. 2.1.1: Added notification method to properly detect whether the associated popup menu and imagelist are deleted. Thanks to

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧