Delphi Get pictures from Twebbrowse components

Source: Internet
Author: User

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

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.