Talk about Delphi Internet Programming Skills (2)

zhaozj2021-02-11  174

Internet programming skills at talking about Delphi (two) Author: Lu Yang E-Mail: lyboy99@sina.com

After telling the first section, I will introduce you to the common usage and techniques of the TwebBrowser control in Delphi. Starting from Delphi5, the TWEBBROWSER component encapsulates with the MS IE AcitVex control and replaced the THTML component from NetMasters. Delphi5 is not all added to the TWEBBROWSER control, we can first install the original TWEBBROWSER component, then install the MS IE ActiveX control from the new Press: Select the Component Menu -> Install Packages appear (as shown in Figure 1-1) screen, select Internet Explorer After the Components Options, press

Remove button, uninstall the original TWEBBROWSER control, then select the Import ActiveX Control menu, such as (Figure 1-2), appear (Figure 1-3), select Microsoft Internet Controls (Version 1.1), install After installation, you will find more WebBrowse_v1 and webbrowse two controls in the ActiveX Components menu.

[Picture 1-1]

[Figure 1-2]

[Figure 1-3]

Take the TWebBrowser (IE5 browser control) as an example, describe the commonly used properties of the following controls. Some properties are not in the TWebBBrowser_v1 control, which is new in the TWEBBROWSER control, I have already indicated in the list below. TWEBBROWSER control common properties table:

Attributes:

Introduction:

Goback

Remove to the previous page

Goforward

Go forward to the next page

Gohome

Call the default home page page

Gosearch

Call the default search page

Navigate (Const URL: WideString)

Var flags, targetframename, posterdata,

Headers: olevariant)

Call the specified page, the specific parameters are as follows:

URL: Specifies the URL of the page. Flags:

Word type, the role is still unclear, can be set to 0.

TargetFramename: WideString,

Open the Frame in the page, when the empty string is currently

Open in Frame; TargetFrameName

The specified Frame is turned on the FRAME;

TargetFraMename specified Frame

When there is no existence, create a window open, it is quite

The IE browser that calls the outside.

PostData: Boolean, whether you are allowed to send data.

Headers: WideString,

Head data to be requested by the URL request

Refresh

Refresh the current page

STOP

Stop call or open the current page

LocationName properties (WIDESTRING)

The name of the current location

LocationURL attribute (WideString)

URL in the current location

Busy property (Boolean),

Is it busy?

Visible: Properties (Boolean)

Is the browser window visible?

Statusbar properties (Boolean)

Whether to display the status bar, TWEBBROWSER has increased

StatusText: Property (WideString)

Status bar content, TWEBBROWSER Add Toolbar: Property (Sysint)

The contents of the toolbar, TWEBBROWSER new

MenuBar: Boolean

Whether to display the menu bar, TWEBBROWSER has increased

Fullscreen: Properties (Boolean)

Whether the full screen is displayed, TWEBBROWSER has increased

OFFLINE: Properties (Boolean)

Whether it takes offline browsing, TWEBBROWSER has increased

AddressBar: Properties (Boolean)

Whether to display the address bar, TWEBBROWSER has increased

TWEBBROWSER FAQ:

OnStatustextChange = Procedure

(Sender: Tobject; Const text: WideString)

Of Object;

When the status bar prompt information, the parameter text is the current status column prompt information, we can update our own status bar prompt information or handle other transactions based on this information.

ONPROGRESSCHANGE = Procedure (Sender: Tobject; Progress, ProgressMax: Integer) OF Object;

When the progress of the page is turned on, the parameter progress is the current progress. ProgressMax is the total progress, and the status bar prompt information or other transactions can be updated according to both parameters.

OnCommandStateChange = Procedure (Sender: Tobject; Command: Integer; Enable: WordBool) OF Object;

When a new command is executed, Command is the command identifier, and the enable is whether the command is allowed.

Ontitlechange = procedure (sender: Tobject; const text: wideString) of object;

When the title of the page changes, Text is the current title.

OnpropertyChange = Procedure (sender: Tobject; const material_: widestring) OF Object;

When the attribute of the page changes, Property_ is the attribute name OndownloadComplete: TNOTIFYEVENT

OndownloadBegin occurred after the download page is completed: TNOTIFYEVENT

Before the download page starts.

After introducing the properties of the TWEBBROWSER control, I will introduce some programming skills to apply the TWEBBROWSER control.

1. Show a GIF animation

If you can't find a control of the GIF animation, one of the following functions can solve your urgent needs.

Procedure showgif (giffileename: string);

VAR

Targetframename, PostData, Heads, Flags: olevariant;

URL: WideString;

Begin

TargetFraMename: = ''; {Specify the empty string of frame,

Open the animation file in the current Frame}

PostData: = false; {does not send data}

HEADS: = ''; {header information is empty}

Flags: = 0; {Flags is set to 0}

URL: = GIFFILENAME;

WITH FORMGIF.WEBBBROWSER DO {in the specified window

IE display animation}

Begin

NaviGate (URL, Flags, TargetFramename

, Poster, heads; {display animation file}

END;

End; 2. Delete the history of IE

I really want to know how to implement the history of deleting IE. The following program case will introduce how to write

Uses Wininet;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR

Cache_INFO: PinternetCachentryInfo;

CBSIZEOF_CACHE_INFO: DWORD;

HW: hwnd;

BUF: TSTRINGS;

Begin

NEW (cache_info);

HW: = FindfirstURLCAENTRYEX (NIL, 0, NORMAL_CACHE_ENTRY or URLHISTORY_CACHE_ENTRY, 0, CACHE_INFO, @ CbsizeOf_Cache_INFO, NIL, NIL, NIL

IF HW <> 0 THEN

Begin

DeleteURLCachentry (cache_info.lpszsourcearcharch);

While FindnextURLCAENTRYEX (HW, cache_info, @ cbsizeof_cache_info, nil, nil, nil) do

DeleteURLCachentry (cache_info.lpszsourcearcharch);

END;

FindCloseurlcache (HW);

Dispose (cache_info);

END;

//Method Two

Type

TSTATURL = Record

CBSIZE: DWORD;

PWCSURL: DWORD;

PWCStitle: DWORD;

FTLASTVISITED: FILETIME;

FTLASTUPDATED: FILETIME;

FTEXPIRES: FILETIME;

DWFLAGS: DWORD;

END;

Type

IEnumstaturl = Interface (IUNKNOWN)

['{3C374A42-BAE4-11CF-BF7D-00AA006946EE}']

Function next (CELT: Integer; Out Elt; PCELTFETCHED: PLONGINT): HRESULT; STDCALL;

Function Skip (CELT: LongInt): HRESULT; stdcall;

Function reset: hresult; stdcall;

Function Clone (Out Ppenum: ienumstaturl): hResult; stdcall;

Function setfilter (POSZFILTER: PWIDECHAR; DWFLAGS: DWORD): HRESULT; stdcall;

END;

Type

IurlhistoryStg = Interface (IUNKNOWN)

[{3C374A41-BAE4-11CF-BF7D-00AA006946EE} ']

Function addurl (PocSurl: PWIDECHAR; Pocstitle: PWIDECHAR; DWFLAGS: Integer): hResult; stdcall;

Function deleteURL (Pocsurl: PWIDECHAR; DWFLAGS: Integer): HRESULT; stdcall;

Function Queryurl (PocSurl: PWIDECHAR; DWFLAGS: Integer; Var LPSTATURL: TSTATURL): HRESULT; stdcall;

Function BindtoObject (Pocsurl: PWIDECHAR; VAR RIID: Tguid; Out PPVOUT: Pointer): HRESULT; stdcall;

Function Enumurls (Out Ppenum: ienumstaturl): hResult; stdcall;

Type

Iurlhistorystg2 = interface (IurlhistorySTG)

['{AFA0DC11-C313-11D0-831A-00c04FD5AE38}']

Function addurlandNotify (PocSurl: PWIDECHAR; Pocstitle: PWIDECHAR; DWFLAGS: Integer

FWRITEHISTORY: Integer; Var POCTNOTIFY: POINTER;

Const Punkisfolder: IUNKNOWN: HRESULT; stdcall;

Function Clearhistory: HRESULT; stdcall;

END;

Function Cleariehistory: integer;

Const

CLSID_CURLHISTORY: TGUID = '{3C374A40-BAE4-11CF-BF7D-00AA006946EE}';

VAR

Iehistory: IurlhistoryStg2;

Begin

Iehistory: = CreateComobject (CLSID_CURLHISTORY) AS IURLHISTORYSTG2;

Iehistory.cleromHistory;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

Cleariehistory;

END;

3. Add to Favorites and finishing favorites

Const

CLSID_SHELLUIHELPER: Tguid = '{64AB4BB7-111E-11D1-8F79-00C04FC2FBE1}';

VAR

P: procedure (Handle: Thandle; Path: pchar); stdcall;

Procedure TFORM1.Organizefavorite (Sender: TOBJECT);

VAR

H: hwnd;

Begin

H: = loading (pchar ('shdocvw.dll');

IF H <> 0 THEN

Begin

P: = GetProcaddress (H, Pchar ('Doorganizefavdlg');

IF Assigned (P) THEN P (Application.Handle, Pchar (Favfolder));

END;

Freelibrary (h);

END;

Procedure TFORM1.ADDFAVORITE (Sender: TOBJECT);

VAR

ShelluiHelper: ishelluihelper;

URL, Title: Olevariant;

Begin

Title: = webbrowser1.locationname;

URL: = WebBrowser1.LocationURL;

IF URL <> '' THEN

Begin

ShelluiHelper: = CreateComobject (clsid_shelluihelper) as ithelluihelper;

ShelluiHelper.Addfavorite (URL, TITLE);

END;

END;

4. Get the web source code and HTML directly from TWEBBROWSER

Memo1.Lines.Add (IHTMLDocument2 (WebBrowser1.Document) .Body.outerHTML;

If you use TWEBBROWSER to browse the HTML file, you will be very simple, Memo1.Lines.Add (Ihtmldocument2 (WebBrowser1.Document); Body.outerText);

5. Get the Handle of the IE address bar

VAR

FORM1: TFORM1;

IMPLEMentation

{$ R * .dfm}

Function getURL (h: hwnd; lparam: longint): boolean; stdcall;

Var Str, URL: Array [0..254] of char;

Begin

GetClassName (H, @ STR, 255);

If strpas (@str) = 'ComboBoxEx32' Then // ComboBoxEx32 can be changed to Edit.

Begin

SendMessage (H, WM_Gettext, 255, longint (@url));

SendMessage (H, WM_SETTEXT, 255, Longint (pchar ('http://www.sina.com)));

SendMessage (H, WM_KeyDown, VK_RETURN, 1);

Form1.ListBox1.Items.add (StrPas (@url));

END;

RESULT: = TRUE;

END;

Function CallbackProc (h: hwnd; lparam: longint): boolean; stdcall;

Var Str: array [1..255] of char;

Begin

GetClassName (H, @ STR, 255);

IF ((@str) = 'CabinetWClass') or (StrPas (@str) = 'iframe')) Then

Begin

EnumchildWindows (h, @ geturl, 0);

END;

RESULT: = TRUE;

END;

Procedure TFORM1.FindButtonClick (Sender: TOBJECT);

Begin

Listbox1.clear;

Enumwindows (@ CallbackProc, 0);

END;

End.

转载请注明原文地址:https://www.9cbs.com/read-6008.html

New Post(0)