[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
[Files]
Source: CallbackCtrl.dll; Flags: dontcopy
[Code]
type
TPBProc = function (h:hWnd;Msg,wParam,lParam:Longint):Longint;
var
TimeLeftLabel, Progress : TLabel;
PBOldProc : Longint;
WFCaption : string;
eTime, sTime : DWORD;
function SetWindowLong(hWnd: HWND; nIndex: Integer; dwNewLong: Longint): Longint; external 'SetWindowLongA@user32.dll stdcall';
function CallBackProc(P:TPBProc;ParamCount:integer):LongWord; external 'wrapcallbackaddr@files:CallbackCtrl.dll stdcall';
function CallWindowProc(lpPrevWndFunc: Longint; hWnd: HWND; Msg: UINT; wParam, lParam: Longint): Longint; external 'CallWindowProcA@user32.dll stdcall';
function GetTickCount: DWORD; external 'GetTickCount@kernel32.dll stdcall';
function LongintToStringTime(t:Longint):string;
var
h,m,s:integer;
begin
h:=t div 3600;
t:=t-h*3600;
m:=t div 60;
s:=t-m*60;
Result:='';
if h>0 then Result:=Result+IntToStr(h)+' ч. ';
if (m>0) or (h>0) then Result:=Result+IntToStr(m)+' мин. ';
if (m>0) or (h>0) or (s>0) then Result:=Result+IntToStr(s)+' сек.';
end;
function PBProc(h:hWnd;Msg,wParam,lParam:Longint):Longint;
var
lt:Longint;
dt,at,pr,i1,i2:Extended;
p:string;
tc:DWORD;
begin
Result:=CallWindowProc(PBOldProc,h,Msg,wParam,lParam);
if (Msg=$402) and (WizardForm.ProgressGauge.Position>WizardForm.ProgressGauge.Min) then begin
i1:=WizardForm.ProgressGauge.Position-WizardForm.ProgressGauge.Min;
i2:=WizardForm.ProgressGauge.Max-WizardForm.ProgressGauge.Min;
tc:=GetTickCount;
if (tc-eTime)>=1000 then begin
dt:=(tc-sTime)/1000;
at:=i2*dt/i1;
lt:=Round(at-dt)
TimeLeftLabel.Caption:='Осталось - '+LongintToStringTime(lt);
eTime:=tc;
end;
pr:=i1*100/i2;
p:='Прогресс - '+Format('%f',[pr])+'%';
StringChange(p,',','.');
Progress.Caption:=p;
end;
end;
procedure AllCancel;
begin
SetWindowLong(WizardForm.ProgressGauge.Handle,-4,PBOldProc);
TimeLeftLabel.Free;
WizardForm.Caption:=WFCaption;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
case CurStep of
ssInstall: begin
WFCaption:=WizardForm.Caption;
TimeLeftLabel:=TLabel.Create(nil);
with TimeLeftLabel do begin
Parent:=WizardForm.InstallingPage;
AutoSize:=False;
SetBounds(0,70,417,21);
end;
Progress:=TLabel.Create(nil);
with Progress do begin
Parent:=WizardForm.InstallingPage;
AutoSize:=False;
SetBounds(0,90,417,21);
end;
sTime:=GetTickCount;
eTime:=sTime;
PBOldProc:=SetWindowLong(WizardForm.ProgressGauge.Handle,-4,CallBackProc(@PBProc,4));
end;
ssPostInstall: AllCancel;
end;
end;