2012-04-12 166 views
6

我準備了一個簡單的腳本,在wpInstalling頁面的ProgressGauge欄中顯示圖像。Inno Setup - 在ProgressGauge下的wpInstalling頁面上顯示多個圖像(幻燈片)

但是...我需要更復雜的功能。我需要的是多個圖像顯示,每個圖像顯示X(例如7)秒(安裝時長度超過X秒*圖像數量)或X(例如10%)安裝後的每個圖像。我試圖在ProgressGauge.Position中嵌入圖像顯示,但是我失敗了。

以下是我有:

procedure CurPageChanged(CurPageID: Integer); 
var 
    BmpFile: TBitmapImage; 
begin 
    ExtractTemporaryFile('01.bmp'); 
    ExtractTemporaryFile('02.bmp'); 
    ExtractTemporaryFile('03.bmp'); 

    if CurPageID = wpInstalling then 
    begin 
    BmpFile:= TBitmapImage.Create(WizardForm); 
    BmpFile.Bitmap.LoadFromFile(ExpandConstant('{tmp}\01.bmp')); 
    BmpFile.Width:= ScaleX(420); 
    BmpFile.Height:= ScaleY(180); 
    BmpFile.Left := WizardForm.ProgressGauge.Left + ScaleX(0); 
    BmpFile.Top := WizardForm.ProgressGauge.Top + ScaleY(35); 

    // BmpFile.Parent:= WizardForm.InstallingPage; 
    // BmpFile:= TBitmapImage.Create(WizardForm); 
    // BmpFile.Bitmap.LoadFromFile(ExpandConstant('{tmp}\03.bmp')); 
    // BmpFile.Width:= ScaleX(420); 
    // BmpFile.Height:= ScaleY(400); 
    // BmpFile.Left := WizardForm.ProgressGauge.Left + ScaleX(0); 
    // BmpFile.Top := WizardForm.ProgressGauge.Top + ScaleY(35); 
    // BmpFile.Parent:= WizardForm.InstallingPage; 

    // BmpFile:= TBitmapImage.Create(WizardForm); 
    // BmpFile.Bitmap.LoadFromFile(ExpandConstant('{tmp}\03.bmp')); 
    // BmpFile.Width:= ScaleX(420); 
    // BmpFile.Height:= ScaleY(400); 
    // BmpFile.Left := WizardForm.ProgressGauge.Left + ScaleX(0); 
    // BmpFile.Top := WizardForm.ProgressGauge.Top + ScaleY(35); 
    // BmpFile.Parent:= WizardForm.InstallingPage; 
    end; 
end; 

的目標是:
wpInstalling應該有顯示的X圖像,每X秒或安裝的X%之後,每一個後續。

回答

7

由於ProgressGauge沒有進度更改事件,並且無法處理設置應用程序消息,因此您需要使用Windows API計時器。這個計時器需要一個回調函數,你不能在Inno Setup腳本中定義,所以你需要一些外部庫來爲你完成這項工作。然而,有InnoCallback庫可以做到這一點。

對於下面的代碼InnoCallback.dll庫複製到你的安裝目錄下,合併該代碼與您的Inno Setup的腳本,並實現某種在OnSlideTimer事件的幻燈片翻頁將被定期調用的(與當前設置的每個第二)。

[Files] 
Source: "InnoCallback.dll"; DestDir: "{tmp}"; Flags: dontcopy 

[code] 
var 
    TimerID: Integer; 

type 
    TTimerProc = procedure(Wnd: HWND; Msg: UINT; TimerID: UINT_PTR; 
    SysTime: DWORD); 

function WrapTimerProc(Callback: TTimerProc; ParamCount: Integer): LongWord; 
    external '[email protected]:InnoCallback.dll stdcall';  
function SetTimer(hWnd: HWND; nIDEvent, uElapse: UINT; 
    lpTimerFunc: UINT): UINT; external '[email protected] stdcall'; 
function KillTimer(hWnd: HWND; uIDEvent: UINT): BOOL; 
    external '[email protected] stdcall'; 

procedure OnSlideTimer(Wnd: HWND; Msg: UINT; TimerID: UINT_PTR; 
    SysTime: DWORD); 
begin 
    { here you can turn your slideshow pages; use some variable to store the } 
    { current index of the slide you are on, note that this procedure is called } 
    { periodically each 1000 ms (see below why), so here you can also check the } 
    { progress value, if you want to } 
end; 

procedure StartSlideTimer; 
var 
    TimerCallback: LongWord; 
begin 
    TimerCallback := WrapTimerProc(@OnSlideTimer, 4); 
    { third parameter here is the timer's timeout value in milliseconds } 
    TimerID := SetTimer(0, 0, 1000, TimerCallback); 
end; 

procedure KillSlideTimer; 
begin 
    if TimerID <> 0 then 
    begin 
    if KillTimer(0, TimerID) then 
     TimerID := 0; 
    end; 
end; 

function InitializeSetup: Boolean; 
begin 
    Result := True; 
    TimerID := 0; 
end; 

procedure DeinitializeSetup; 
begin 
    KillSlideTimer; 
end; 

procedure CurPageChanged(CurPageID: Integer); 
begin 
    if CurPageID = wpInstalling then 
    StartSlideTimer 
    else 
    KillSlideTimer; 
end; 
+0

這解決了我的問題! 我已添加全局變量索引:Integer;並稍微修改圖像代碼(IntToStr) – RobeN 2012-04-13 09:14:36

+1

是的,那裏你可以有時間計數器或訪問進度表,如果你需要。這就是爲什麼我只展示瞭如何爲你實現計時器事件的原因;-)但是,也許你應該在那裏檢查進度表狀態,因爲如果發生錯誤,它看起來不太好,你仍然會旋轉你的幻燈片。我想你應該只在'WizardForm.ProgressGauge.State = npbsNormal'時滑動你的圖片,但它也是你的。請參閱['here'](http://www.jrsoftware.org/ishelp/topic_scriptclasses.htm#TNewProgressBarState)瞭解可用的進度狀態。 – TLama 2012-04-13 09:25:03

+1

我做到了。 「暫停」,「錯誤」和「位置=最大」的特殊功能(第三方應用安裝期間)。感謝您的幫助和支持! – RobeN 2012-04-13 13:46:56

2

爲什麼不在每個文件條目上使用AfterInstall來更改圖像?

+0

這不是我所需要的。 TLama的解決方案更好(至少對我而言)。 – RobeN 2012-04-16 10:06:39

+0

將很高興看到您的工作示例...我仍然有問題使此腳本正常工作。 – Dielo 2013-03-04 10:24:40