演示: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;
这样基本上就可以了。