PasswordForm.PageControl1.ActivePageIndex := 1; aJPEGImage := TJPEGImage.Create; s1 := webUrl; nPos := Pos('http://', s1); if (nPos=1) then s1 := Copy(s1, 8, length(s1)-7); nPos := Pos('/', s1); if (nPos>1) then s1 := Copy(s1, 1, nPos); if Webbrowser1.Document <> nil then try webbrowser1.Document.QueryInterface(IViewObject, ViewObject); if ViewObject <> nil then try sourceDrawRect := Rect(0, 0, Image1.Width, Image1.Height); ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle, image1.Canvas.Handle, @sourceDrawRect, nil, nil, 0); image1.Picture.SaveToFile('./'+s1 +'.bmp'); aJPEGImage.Assign(image1.Picture.Graphic); aJPEGImage.SaveToFile('./'+s1+'.jpg'); finally ViewObject._Release; end; except end; aJPEGImage.free; PasswordForm.Caption := 'Completed'; PasswordForm.PageControl1.ActivePageIndex := 0; PasswordForm.Hide; end; end. DLLUnit.pas unit DllUnit; interface uses SysUtils, Classes; function GetString: string; export; implementation function GetString : string ; export ; begin GetString := 'Hello from the DLL!' ; end ; end. WebCap.dpr library WebCap; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses PassForm in 'PASSFORM.PAS' {PasswordForm}; {$R *.res} exports InitCap, CloseCap, GetWebImage ; begin end. ------- 下面是 调用这个DLL的例子: unit PassForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, OleCtrls, SHDocVw, ComCtrls, jpeg, ActiveX; type TPasswordForm = class(TForm) PageControl1: TPageControl; TabSheet1: TTabSheet; WebBrowser1: TWebBrowser; TabSheet2: TTabSheet; Image1: TImage; procedure WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); private webUrl : String; _width : Integer; _height : Integer; public { Public declarations } end; var PasswordForm: TPasswordForm; procedure InitCap(width : integer; height : integer ); export; procedure GetWebImage(url: PChar); export; procedure CloseCap(); export; implementation {$R *.dfm} procedure InitCap(width : integer; height : integer ); begin PasswordForm := TPasswordForm.Create(nil); PasswordForm._width := width; PasswordForm._height := height; end; procedure GetWebImage(url: PChar); begin if PasswordForm = nil then begin ShowMessage('Call InitCap(320, 220) first!'); exit; end; with PasswordForm do begin webUrl := url; webBrowser1.Navigate(url); Caption := 'Getting ....' + url; Show; end; end; procedure CloseCap(); begin PasswordForm.Free; end; procedure TPasswordForm.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var ViewObject: IViewObject; sourceDrawRect: TRect; aJPEGImage : TJPEGImage; s1 : string; nPos : integer; begin PasswordForm.Image1.Width := PasswordForm._width; PasswordForm.Image1.Height := PasswordForm._Height;
可以嵌入到见面中去。
Unit1.Pas
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; procedure GetWebImage (url : string); far ; external 'WebCap' ;
procedure InitCap (width : integer; height : integer); far ; external 'WebCap' ;
procedure CloseCap (); far ; external 'WebCap' ;
implementation {$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
InitCap(StrToInt(Edit2.Text), StrtoInt(Edit3.Text));
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetWebImage (edit1.Text);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
CloseCap();
Button1.Enabled := False;
Button2.Enabled := True;
Button3.Enabled := False;
end; end. PasswordForm.pas
unit PassForm; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, OleCtrls, SHDocVw, ComCtrls, jpeg, ActiveX; type
TPasswordForm = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
WebBrowser1: TWebBrowser;
TabSheet2: TTabSheet;
Image1: TImage;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
webUrl : String;
_width : Integer;
_height : Integer;
public
{ Public declarations }
end; var
PasswordForm: TPasswordForm; procedure InitCap(width : integer; height : integer ); export;
procedure GetWebImage(url: PChar); export;
procedure CloseCap(); export; implementation {$R *.dfm} procedure InitCap(width : integer; height : integer );
begin
PasswordForm := TPasswordForm.Create(nil);
PasswordForm._width := width;
PasswordForm._height := height;
end; procedure GetWebImage(url: PChar);
begin
if PasswordForm = nil then
begin
ShowMessage('Call InitCap(320, 220) first!');
exit;
end; with PasswordForm do
begin
webUrl := url;
webBrowser1.Navigate(url);
Caption := 'Getting ....' + url;
Show;
end;
end; procedure CloseCap();
begin
PasswordForm.Free;
end;
procedure TPasswordForm.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
ViewObject: IViewObject;
sourceDrawRect: TRect;
aJPEGImage : TJPEGImage;
s1 : string;
nPos : integer;
begin PasswordForm.Image1.Width := PasswordForm._width;
PasswordForm.Image1.Height := PasswordForm._Height;
PasswordForm.PageControl1.ActivePageIndex := 1; aJPEGImage := TJPEGImage.Create; s1 := webUrl;
nPos := Pos('http://', s1);
if (nPos=1) then s1 := Copy(s1, 8, length(s1)-7);
nPos := Pos('/', s1);
if (nPos>1) then s1 := Copy(s1, 1, nPos); if Webbrowser1.Document <> nil then
try
webbrowser1.Document.QueryInterface(IViewObject, ViewObject);
if ViewObject <> nil then
try
sourceDrawRect := Rect(0, 0, Image1.Width, Image1.Height);
ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle,
image1.Canvas.Handle, @sourceDrawRect, nil, nil, 0);
image1.Picture.SaveToFile('./'+s1 +'.bmp');
aJPEGImage.Assign(image1.Picture.Graphic);
aJPEGImage.SaveToFile('./'+s1+'.jpg');
finally
ViewObject._Release;
end;
except
end;
aJPEGImage.free; PasswordForm.Caption := 'Completed';
PasswordForm.PageControl1.ActivePageIndex := 0;
PasswordForm.Hide;
end; end. DLLUnit.pas
unit DllUnit; interface uses
SysUtils, Classes; function GetString: string; export; implementation function GetString : string ; export ;
begin
GetString := 'Hello from the DLL!' ;
end ;
end. WebCap.dpr
library WebCap; { Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. } uses
PassForm in 'PASSFORM.PAS' {PasswordForm};
{$R *.res} exports
InitCap,
CloseCap,
GetWebImage ; begin end. ------- 下面是 调用这个DLL的例子:
unit PassForm; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, OleCtrls, SHDocVw, ComCtrls, jpeg, ActiveX; type
TPasswordForm = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
WebBrowser1: TWebBrowser;
TabSheet2: TTabSheet;
Image1: TImage;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
webUrl : String;
_width : Integer;
_height : Integer;
public
{ Public declarations }
end; var
PasswordForm: TPasswordForm; procedure InitCap(width : integer; height : integer ); export;
procedure GetWebImage(url: PChar); export;
procedure CloseCap(); export; implementation {$R *.dfm} procedure InitCap(width : integer; height : integer );
begin
PasswordForm := TPasswordForm.Create(nil);
PasswordForm._width := width;
PasswordForm._height := height;
end; procedure GetWebImage(url: PChar);
begin
if PasswordForm = nil then
begin
ShowMessage('Call InitCap(320, 220) first!');
exit;
end; with PasswordForm do
begin
webUrl := url;
webBrowser1.Navigate(url);
Caption := 'Getting ....' + url;
Show;
end;
end; procedure CloseCap();
begin
PasswordForm.Free;
end;
procedure TPasswordForm.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
ViewObject: IViewObject;
sourceDrawRect: TRect;
aJPEGImage : TJPEGImage;
s1 : string;
nPos : integer;
begin PasswordForm.Image1.Width := PasswordForm._width;
PasswordForm.Image1.Height := PasswordForm._Height;
PasswordForm.PageControl1.ActivePageIndex := 1; aJPEGImage := TJPEGImage.Create; s1 := webUrl;
nPos := Pos('http://', s1);
if (nPos=1) then s1 := Copy(s1, 8, length(s1)-7);
nPos := Pos('/', s1);
if (nPos>1) then s1 := Copy(s1, 1, nPos); if Webbrowser1.Document <> nil then
try
webbrowser1.Document.QueryInterface(IViewObject, ViewObject);
if ViewObject <> nil then
try
sourceDrawRect := Rect(0, 0, Image1.Width, Image1.Height);
ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle,
image1.Canvas.Handle, @sourceDrawRect, nil, nil, 0);
image1.Picture.SaveToFile('./'+s1 +'.bmp');
aJPEGImage.Assign(image1.Picture.Graphic);
aJPEGImage.SaveToFile('./'+s1+'.jpg');
finally
ViewObject._Release;
end;
except
end;
aJPEGImage.free; PasswordForm.Caption := 'Completed';
PasswordForm.PageControl1.ActivePageIndex := 0;
PasswordForm.Hide;
end; end.
这个是某位高人的源码,我不知道什么意思,也不会用!!!唉~~~~~~帮帮我
http://yjmyzz.cnblogs.com/