[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
[Files]
Source: "tb.dll"; Flags: "dontcopy";
Source: "CallbackCtrl.dll"; Flags: "dontcopy";
Source: {win}\help\*; DestDir: {app}\Files; Flags: external recursesubdirs
[Code]
const
TBPF_NOPROGRESS = 0;
TBPF_INDETERMINATE = 1;
TBPF_NORMAL = 2;
TBPF_ERROR = 4;
TBPF_PAUSED = 8;
type
PWideChar = String;
TPBProc = function (h: hWnd; Msg, wParam, lParam: Longint): Longint;
var
eTime,sTime: DWORD;
PBOldProc: Longint;
WFCaption: string;
// tb.dll
procedure SetTaskBarThumbnailClip(Left, Top, Bottom, Right: Integer); external 'SetTaskBarThumbnailClip@{tmp}\tb.dll stdcall delayload';
procedure SetTaskBarProgressValue(Value: Integer); external 'SetTaskBarProgressValue@{tmp}\tb.dll stdcall delayload';//
procedure SetTaskBarProgressState(Value: Integer); external 'SetTaskBarProgressState@{tmp}\tb.dll stdcall delayload';//
procedure SetTaskBarTitle(const Caption: PWideChar); external 'SetTaskBarTitle@{tmp}\tb.dll stdcall delayload';//
procedure SetTaskBarThumbnailTooltip(const Caption: PWideChar); external 'SetTaskBarThumbnailTooltip@{tmp}\tb.dll stdcall delayload';//
//win api
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';
procedure DeInitTB; forward;
function InitializeSetup: Boolean;
begin
if not FileExists(ExpandConstant('{tmp}\tb.dll')) then ExtractTemporaryFile('tb.dll');
if not FileExists(ExpandConstant('{tmp}\CallbackCtrl.dll')) then ExtractTemporaryFile('CallbackCtrl.dll');
Result:=True;
end;
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
dt,at,pr,i1,i2: Extended;
lt: Longint;
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;
pr:=i1*100/i2;
p:=Format('%f',[pr])+'%';
StringChange(p,',','.');
SetTaskBarThumbnailTooltip(p); //Set caption (Hint caption, at OnMouseEnter on miniature) for TaskBarProgress
SetTaskBarProgressValue(Round(pr)); //Set position for TaskBarProgress
SetTaskBarThumbnailClip(ScaleX(0), ScaleX(0), ScaleX(40), ScaleY(80)); //Resize miniature
tc:=GetTickCount;
if (tc-eTime)>=1000 then begin
dt:=(tc-sTime)/1000;
at:=i2*dt/i1;
lt:=Round(at-dt);
SetTaskBarTitle('Жди ~ '+LongintToStringTime(lt)+' ('+p+').'); //Set caption for TaskBarProgress
eTime:=tc;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
case CurStep of
ssInstall: begin
WFCaption:=WizardForm.Caption;
SetTaskBarProgressValue(1000); //Set max value for TaskBarProgress
sTime:=GetTickCount; eTime:=sTime;
PBOldProc:=SetWindowLong(WizardForm.ProgressGauge.Handle,-4,CallBackProc(@PBProc,4));
end;
ssPostInstall: DeInitTB;
end;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if CurPageID=wpInstalling then begin
Confirm:=False;
Cancel:=ExitSetupMsgBox;
if Cancel then DeInitTB;
end;
end;
procedure DeInitTB;
begin
SetWindowLong(WizardForm.ProgressGauge.Handle, -4, PBOldProc);
WizardForm.Caption:=WFCaption;
end;