Using the Twebbrowse component in Delphi is not as efficient as using (Idhttp and the like) analog operations. But it is difficult, quick to get started, simple and rough effective.
Most of the articles from the web that deal with this issue are the method of copying Ctrl + C to the Clipboard, but in Win7 64, this method is almost impossible to use and to report Clipboard errors at any time.
This method solves the problem perfectly by using the Ihtmlelementrender interface. At the same time, further understanding of the interface can be deepened.
Delphi7 Source Download
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrls, Olectrls, S HDOCVW, MSHtml;type //This definition was copied from XE8 's MSHTML unit .Ihtmlelementrender =Interface(IUnknown) ['{3050f669-98b5-11cf-bb82-00aa00bdce0b}'] functionDRAWTODC (HDC:HDC): HResult;stdcall; functionSetdocumentprinter (Constbstrprintername:widestring; HDC:HDC): HResult;stdcall; End; TForm1=class(tform) Webbrowser1:twebbrowser; Image1:timage; Button1:tbutton; procedureformcreate (Sender:tobject); procedureformshow (Sender:tobject); procedureButton1Click (Sender:tobject); PrivateFfirstshow:boolean; Fcodebmp:tbitmap; End;varForm1:tform1;ImplementationConstcsURL='https://account.guokr.com/sign_in/?';{$R *.DFM}proceduretform1.formcreate (sender:tobject);beginffirstshow:=true; Fcodebmp:= Tbitmap.Create; Fcodebmp.height:= +; Fcodebmp.width:= -; Fcodebmp.pixelformat:=Pf24bit;End;proceduretform1.formshow (sender:tobject);begin //do a firstonshow function. //If you use WebBrowser1.Navigate in the OnCreate event, it will go wrong. ifFfirstshow Then beginwebbrowser1.navigate (csURL); Ffirstshow:=false; End;End;procedureTform1.button1click (sender:tobject);varDoc:ihtmldocument2; Render:ihtmlelementrender;beginDoc:= Webbrowser1.document asIHTMLDocument2; Render:= Doc.All.Item ('Captchaimage', Emptyparam) asIhtmlelementrender; RENDER.DRAWTODC (Self.Canvas.Handle); RENDER.DRAWTODC (FCodeBmp.Canvas.Handle); Image1.Picture.Assign (fcodebmp);End;End.
Delphi Get pictures from Twebbrowse components