H
hying95
Unregistered / Unconfirmed
GUEST, unregistred user!
现在DLL中的窗体能够正常显示GIF动画了,代码如下:unit UChildForm;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, ExtCtrls,GIFImage, StdCtrls;type TDLLChildForm = class(TForm) img1: TImage; btn1: TSpeedButton; pnl4: TPanel; btn2: TSpeedButton; Edit1: TEdit; btn3: TSpeedButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); procedure btn3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var DLLChildForm: TDLLChildForm; TmpGif: TGIFImage; img: TImage; stop: Boolean=false; N: Integer=0;procedure InitDLL(AHandle: Thandle); stdcall;procedure FreeDLL; stdcall;function ShowFrmMN(AHandle:THandle):BOOL;stdcall;implementation{$R *.dfm}{$R GifRc.RES}procedure FreeDLL; stdcall;begin if DLLChildForm= nil then begin Exit; end; DLLChildForm.Release; PostMessage(Application.Handle, WM_QUIT, 0, 0); DLLChildForm := nil;end;function ShowFrmMN(AHandle:THandle):BOOL;stdcall;begin Application.Initialize; Application.Handle:=AHandle; DLLChildForm:=TDLLChildForm.Create(Application); try DLLChildForm.ShowModal; Application.Run; Result:=False; Finally DLLChildForm.Free; end;end;procedure InitDLL(AHandle: Thandle); stdcall;begin Application.Initialize; Application.ShowMainForm := False; Application.CreateForm(TDLLChildForm, DLLChildForm); DLLChildForm.Tag := Application.Handle; Application.Handle := AHandle; Application.Run; Application.Handle := DLLChildForm.Tag;end;procedure TDLLChildForm.btn1Click(Sender: TObject);var TMPGif: TGIFImage; I: Integer;begin TMPGif:=TGIFImage.Create; TmpGif.LoadFromFile('d:/head3.gif'); img1.Height:=TMPGif.Height; img1.Width:=TMPGif.Width; img1.Picture.Assign(TMPGif); stop:=False;//**********************************{注释*号间这段循环动画会动,加了后就不动,但如果不在DLL中加了循环动画也会动不知道为什么?有没有哪位富翁能搞定这个} for i:=0 to 20000000 do begin Application.ProcessMessages; if stop then begin Break; end; n:=i+n; Edit1.Text :=IntToStr; end;//********************************************** TMPGif.Free;end;DLL工程:library ppp;uses SysUtils, Classes, UChildForm in 'UChildForm.pas' {DLLChildForm}, GIFImage in '../GifImage.pas';{$R *.res}exports ShowFrmMN, InitDLL, FreeDLL;beginend.调用var Form1: TForm1; procedure InitDLL(AHandle: Thandle); stdcall; external 'ppp.dll'; procedure DestoryDLL; stdcall; external 'ppp.dll'; function ShowFrmMN(AHandle:THandle):BOOL;stdcall; external 'ppp.dll';implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);begin ShowFrmMN(Application.Handle); InitDLL(0);end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin DestoryDLLend;