1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| function SaveWebBrowserToBmp(aWebBrowser :TWebBrowser; aFileName :TFileName) :boolean;
var
Doc :IHTMLDocument2;
View :IViewObject;
Rect :TRect;
begin
Result := FALSE;
Doc := aWebBrowser.Document as IHTMLDocument2;
if Assigned(Doc.Body) then
begin
//Largeur du WebBrowser à la largeur de l'écran et
//récupération de la hauteur nécessaire
aWebBrowser.Width := Screen.Width;
aWebBrowser.Height := (Doc.Body as IHTMLElement2).ScrollHeight;
//Masque les ScrollBars
Doc.Body.Style.Overflow := 'hidden';
with TBitmap.Create do
try
Width := aWebBrowser.Width;
Height := aWebBrowser.Height;
Rect := Bounds(0, 0, Width, Height);
//Dessin
Doc.QueryInterface(IViewObject, View);
View.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, Canvas.Handle, @Rect, nil, nil, 0) ;
//Sauvegarde
SaveToFile(aFileName);
Result := TRUE;
finally
Free;
end;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
SaveWebBrowserToBmp(WebBrowser1, 'c:\temp\Developpez.bmp');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
URL :OleVariant;
begin
URL := 'http://www.developpez.net/forums/f15/environnements-developpement/delphi/';
webbrowser1.Navigate2(URL);
end; |
Partager