我们使用以下代码在完成页面上显示图像(幻灯片放映)。
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "Image1.bmp"; Flags: dontcopy
Source: "Image2.bmp"; Flags: dontcopy
Source: "Image3.bmp"; Flags: dontcopy
Source: "InnoCallback.dll"; Flags: dontcopy
[Code]
var
TimerID: Integer;
SlideID: Integer;
BackImage: TBitmapImage;
Panel: TPanel;
type
TTimerProc = procedure(Wnd: HWND; Msg: UINT; TimerID: UINT_PTR; SysTime: DWORD);
TDirectShowEventProc = procedure(EventCode, Param1, Param2: Integer);
function WrapTimerProc(Callback: TTimerProc; ParamCount: Integer): LongWord;
external 'wrapcallback@files:InnoCallback.dll stdcall';
function SetTimer(hWnd: HWND; nIDEvent, uElapse: UINT; lpTimerFunc: UINT): UINT; external 'SetTimer@user32.dll stdcall';
function KillTimer(hWnd: HWND; uIDEvent: UINT): BOOL;
external 'KillTimer@user32.dll stdcall';
procedure URLOnClick(Sender: TObject);
var
ErrorCode: Integer;
begin
ShellExec('open', 'http://www.google.com/', '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
end;
procedure OnSlideTimer(Wnd: HWND; Msg: UINT; TimerID: UINT_PTR; SysTime: DWORD);
begin
case SlideID of
0: SlideID := 1;
1: SlideID := 2;
2: SlideID := 0;
end;
BackImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\Image' + IntToStr(SlideID + 1) + '.bmp'));
end;
procedure StartSlideTimer;
var
TimerCallback: LongWord;
begin
TimerCallback := WrapTimerProc(@OnSlideTimer, 4);
TimerID := SetTimer(0, 0, 2000, TimerCallback);
end;
procedure InitializeWizard;
var
ContentHeight: Integer;
begin
TimerID := 0;
SlideID := 0;
ContentHeight := WizardForm.OuterNotebook.Top + WizardForm.OuterNotebook.Height;
ExtractTemporaryFile('Image1.bmp');
ExtractTemporaryFile('Image2.bmp');
ExtractTemporaryFile('Image3.bmp');
Panel := TPanel.Create(WizardForm);
Panel.Parent := WizardForm;
Panel.Left := 200;
Panel.Top := WizardForm.OuterNotebook.Top + 200;
Panel.Width := ScaleX(220);
Panel.Height := ScaleY(40);
Panel.Visible := False;
BackImage := TBitmapImage.Create(WizardForm);
BackImage.Parent := Panel;
BackImage.Width:= ScaleX(210);
BackImage.Height:= ScaleY(35);
BackImage.Left := (Panel.Height - BackImage.Height) div 2;
BackImage.Top := (Panel.Height - BackImage.Height) div 2;
BackImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\Image1.bmp'));
BackImage.OnClick := @URLOnClick;
StartSlideTimer;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
Panel.Visible := CurPageID = wpFinished;
end;
我的问题是,这里的图像会每2秒更改一次。如果我点击Image1,它应该打开google.com,如果我点击Image2,它应该打开Yahoo.com。
请帮帮我。
答案 0 :(得分:3)
您知道哪个幻灯片显示在SlideID
变量中,并且您正在使用名为URLOnClick
的图片点击事件方法(对于此类事件方法而言,这不是一个好名字。)。所以只需这样修改事件方法:
procedure URLOnClick(Sender: TObject);
var
URL: string;
ErrorCode: Integer;
begin
URL := '';
case SlideID of
0: URL := 'http://www.google.com/'; // <- Image1
1: URL := 'http://www.yahoo.com/'; // <- Image2
end;
if URL <> '' then
ShellExec('open', URL, '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
end;