Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Аватара для Johny777

Ветеран


Сообщения: 649
Благодарности: 444

Профиль | Отправить PM | Цитировать


Цитата wertulll:
подскажите код для отображения этого »
насчёт лейбла с отображением прошедшего времени не знаю
а вот с процентами и оставшимся временем дела обстоят хорошо!

читать дальше »
Код: Выделить весь код
[Setup]
AppName=ProgressBar + TimeLeft v2 by South.Tver
AppVerName=ProgressBar + TimeLeft v2 by South.Tver
DefaultDirName={pf}\ProgressBar + TimeLeft v2
OutputBaseFilename=setup

[Files]
Source: {win}\help\*; DestDir: {app}\Files; Flags: external recursesubdirs
Source: {fonts}\*; DestDir: {app}; Flags: external;

Source: CallbackCtrl.dll; Flags: dontcopy
Source: InnoCallback.dll; Flags: dontcopy


[  Code]
type
  TPBProc = function (h:hWnd;Msg,wParam,lParam:Longint):Longint;
  TTimerProc = procedure(HandleW, Msg, idEvent, TimeSys: LongWord);  /// проценты

var
  TimeLeftLabel : TLabel;

  PBOldProc     : Longint;
  WFCaption     : string;
  eTime, sTime  : DWORD;
///////////////////////////////// проценты /// начало
  PercentsTimer: LongWord;
  PercentsLabel: TLabel;

function WrapTimerProc(callback: TTimerProc; Paramcount: Integer): longword; external 'wrapcallback@files:innocallback.dll stdcall';
function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): longword; external 'SetTimer@user32';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord; external 'KillTimer@user32 stdcall delayload';
/////////////////////////////////////////// конец
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 NumToStr(Float: Extended): String;
begin
  Result:= Format('%.1n', [Float]); StringChange(Result, ',', '.');
  while ((Result[Length(Result)] = '0') or (Result[Length(Result)] = '.')) and (Pos('.', Result) > 0) do
  SetLength(Result, Length(Result)-1);
End;

Procedure PercentsProc(h, msg, idevent, dwTime: Longword);
Begin
  with WizardForm.ProgressGauge do
  begin
    PercentsLabel.Caption:= 'Выполнено ' + NumToStr((Position*100)/Max) + ' %';
  end;
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
  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 //пересчитывем время оставшееся до конца установки не чаще, чем раз в 1 секунду
      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,',','.');
  end;
end;

procedure AllCancel;
begin
  SetWindowLong(WizardForm.ProgressGauge.Handle,-4,PBOldProc);
  TimeLeftLabel.Free;
  PercentsLabel.Free; /// проценты
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\CallbackCtrl.dll')) then ExtractTemporaryFile('CallbackCtrl.dll');
  Result:=True;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  case CurStep of
    ssInstall: begin
    
      MsgBox('Чтобы продлить время установки будут скопированы шрифты и справки',mbInformation,MB_OK); /// чтоб не пугались
    
      PercentsTimer:= SetTimer(0, 0, 100, WrapTimerProc(@PercentsProc, 4));  /// проценты
    
      TimeLeftLabel:=TLabel.Create(nil);
      with TimeLeftLabel do begin
        Parent:=WizardForm.InstallingPage;
        AutoSize:=True;
        SetBounds(WizardForm.ProgressGauge.Left + ScaleX(250),WizardForm.ProgressGauge.Top + ScaleY(30),ScaleY(80),ScaleY(21));
      end;

      ///////////////////// проценты /// начало
      PercentsLabel:= TLabel.Create(nil);
      with PercentsLabel do
      begin
        SetBounds(WizardForm.ProgressGauge.Left + ScaleX(30), WizardForm.ProgressGauge.Top + WizardForm.ProgressGauge.Height + ScaleY(10), WizardForm.StatusLabel.Width, WizardForm.StatusLabel.Height);
        AutoSize:= True;
        Transparent := True;
        Parent:= WizardForm.InstallingPage;
      end;
      /// конец


      sTime:=GetTickCount;
      eTime:=sTime;

      PBOldProc:=SetWindowLong(WizardForm.ProgressGauge.Handle,-4,CallBackProc(@PBProc,4));
    end;
    ssPostInstall: AllCancel;
  end;
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  if CurPageID=wpInstalling then begin
    Confirm:=False;
    Cancel:=ExitSetupMsgBox;
    if Cancel then AllCancel;
  end;
end;

/////// проценты /// начало
procedure DeinitializeSetup();
begin
  KillTimer(0, PercentsTimer);
end;
///////// конец

сделал так что ты можешь стереть проценты и оставить только время установки
немного изменил сами "проценты" (скопипастил создание лейбла у того же примера с которым совмещал )

1. пример процентов из InnoSetup FAQ
2. "оставшееся время" - это пример ProgressBar + TimeLeft v2 by South.Tver (....\Inno Setup 5\Modules\South\botva2_example\progressbar+TimeLeft.iss), но без ботвы

*(перед тем как выложить проверил)

архив с библиотеками

Последний раз редактировалось Johny777, 26-03-2013 в 15:57.

Это сообщение посчитали полезным следующие участники:

Отправлено: 10:51, 08-05-2012 | #1859