0

我们使用下面的代码在完成页面上显示图像(幻灯片)。

[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。

请帮我。

4

1 回答 1

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;
于 2013-05-13T13:22:38.273 回答