演示:http://www.web0000.com/slide.dw
源代碼:http://www.web0000.com/media/source/slide.zip
一、新建一個DLL
二、除第一行外,更改源碼為
uses ShareMem, SysUtils, Forms, Messages, StdCtrls, Variants, Windows, Classes, unit1 in 'unit1.pas' {Form1}; {$R *.res} type PdwGetEvent=function (ACtrl:TComponent;AData:String):string; StdCall; var DLLApp : TApplication; DLLScreen : TScreen; function dwLoad(AParams:String;AApp:TApplication;AScreen:TScreen):TForm;stdcall; var AForm : TForm1; begin // Application := AApp; Screen := AScreen; AForm := TForm1.Create(nil); AForm.Hint := AParams; Result := AForm; end; procedure DLLUnloadProc(dwReason: DWORD); begin if dwReason = DLL_PROCESS_DETACH then begin Application := DLLApp; //恢復 Screen := DLLScreen; end; end; exports dwLoad; begin DLLApp := Application; //保存 DLL 中初始的 Application DLLScreen := Screen; DLLProc := @DLLUnloadProc;//保證卸載時恢復原Application DLLUnloadProc(DLL_PROCESS_DETACH); end.
三、新建一個Form,保存為unit1.pas. 窗體名稱為Form1
四、在合適位置旋轉1個TImage、1個TTimer和3個TButton
五、在TTimer的OnTimer事件中寫入
procedure TForm1.Timer_SlideTimer(Sender: TObject); begin //set tag if Timer_Slide.Tag<3 then begin Timer_Slide.Tag := Timer_Slide.Tag + 1; end else begin Timer_Slide.Tag := 1; end; //change the image src Image_MN.Hint := '{"src":"/media/images/mn/'+IntToStr(Timer_Slide.Tag)+'.jpg"}'; end;
六、3個按鈕的Caption分別為1,2,3,
設置OnEnter事件代碼為
procedure TForm1.Button1Enter(Sender: TObject); begin //Stop the slide timer Timer_Slide.DesignInfo := 0; //set tag Timer_Slide.Tag := StrToIntDef(TButton(Sender).Caption,1); //change the image src Image_MN.Hint := '{"src":"/media/images/mn/'+IntToStr(Timer_Slide.Tag)+'.jpg"}'; end;
設置OnExit事件代碼為
procedure TForm1.Button1Exit(Sender: TObject); begin //start the slide timer Timer_Slide.DesignInfo := 1; end;
這樣基本上就可以了。