The use of Twebbrowser control under Delphi

Source: Internet
Author: User

When the program needs to visit the Web page, Delphi can generally be implemented in two ways. One is through the tidhttp, this way post data needs to be captured by the Web page, etc., to simulate the post submission of the Web page.

The second is through the Twebbrowser control access, this way is relatively simple, now will be a key part of the recent program to record, in case you refer to friends.

First, visit the Web page

WebBrowser1.Navigate (' http://www.baidu.com ');

Second, Prevent pop-up dialog box or page close Webrowser control

Procedure tmyform.webbrowser1windowclosing (Asender:tobject; Ischildwindow:wordbool; var cancel:wordbool); Begin Cancel: = true; End

Third, to get frameset in the frame content of SRC Web site document, because if you use Webbrowser1.documnent.frames to get his document

Procedure Tmyform.webbrowser1documentcomplete (asender:tobject; const Pdisp:idispatch; var url:olevariant); Begin if Rightposex (' input.php ', URL) > 0 then//to determine the URL is required address begin myDocument: = (pdisp as IWebBrowser2). Document as IHTMLDocument2; End END;

Four, get IHTMLDocument2 how to operate

Procedure Tmyform.btlogoutclick (Sender:tobject); var myform:ihtmlformelement; Begin if assigned (myDocument) THEN BEGIN if rightposex (' Judge page title ', Mydocument.title) <= 0 THEN BEGIN MEMO1.LINES.ADD (' You don't Successful landing! '); Exit; End MyForm: = MyDocument.forms.item (' portal ', 0) as IHTMLFormElement; Myform.action: = ' do_logout.php '; MyDocument.parentWindow.execScript (' issubmitlogout = 1 ', ' JavaScript '); (Myform.item (' Logouttype ', 0) as Ihtmlinputelement). Value: = ' typesubmit '; Myform.submit; End End

Prohibit the Page Pop-up dialog box (mainly is the CSDN forum a Warrior's method)

Uses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Olectrls, SHDOCVW, stdctrls,mshtm L, Extctrls, Comctrls, Idbasecomponent, Idcomponent, Idtcpconnection, Idtcpclient,idhttp, IdAntiFreezeBase, Idantifreeze,inifiles,activex; Const WM_DOWNSTART = Wm_user +1000; Type Idochostshowui = Interface (IUnknown) [' {c4d244b0-d43e-11cf-893b-00aa00bdce1a} '] function ShowMessage (hwnd: Thandle; LPSTRTEXT:POLESTR; Lpstrcaption:polestr;dwtype:longint; LPSTRHELPFILE:POLESTR; Dwhelpcontext:longint;var plresult:lresult): HRESULT; stdcall; function ShowHelp (hwnd:thandle; pszhelpfile:polestr; ucommand:integer;dwdata:longint; ptmouse:tpoint; var PDispatchO Bjecthit:idispatch): HRESULT; stdcall; End Twebbrowser = Class (Shdocvw.twebbrowser,idochostshowui) protected function showmessage (hwnd:thandle; Lpstrtext: POLESTR; Lpstrcaption:polestr;dwtype:longint; LPSTRHELPFILE:POLESTR; Dwhelpcontext:longint;var plresult:lresult): HRESULT; stdcall; function ShowHelp (Hwnd:thandle; PSZHELPFILE:POLESTR; Ucommand:integer;dwdata:longint; Ptmouse:tpoint; var pdispatchobjecthit:idispatch): HRESULT; stdcall; End function Twebbrowser.showhelp (hwnd:thandle; pszhelpfile:polestr; Ucommand, Dwdata:integer; ptmouse:tpoint; var PDispa Tchobjecthit:idispatch): HRESULT; Begin Result: = S_FALSE; End function Twebbrowser.showmessage (hwnd:thandle; lpstrtext, lpstrcaption:polestr; dwtype:integer; LpstrHelpfile: POLESTR; Dwhelpcontext:integer; var plresult:lresult): HRESULT; Begin//Plresult: = MessageBoxW (Hwnd,pwchar (lpstrtext), ' No idle test ', 65); Result: = S_OK; End

What you need to study together, leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.