Thema: Timer Reset ?

Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#6

Re: Timer Reset ?

  Alt 21. Feb 2007, 06:51
Guten Morgen,

etwa so habe ich mir das vorgestellt:

Delphi-Quellcode:
type
  TDemoForm = class(TForm)
    ApplicationEvents: TApplicationEvents;
    procedure ApplicationEventsIdle(Sender: TObject; var Done: Boolean);
    procedure ApplicationEventsActivate(Sender: TObject);
  private
    LastInput: Cardinal;
  end;

{
  ...
}


const
  MAX_APPIDLE_TICKS = 5000;

procedure TDemoForm.ApplicationEventsActivate(Sender: TObject);
begin
  LastInput := GetTickCount;
end;

procedure TDemoForm.ApplicationEventsIdle(Sender: TObject;
  var Done: Boolean);
var
  lii: TLastInputInfo;
begin
  if Application.Active then
  begin
    lii.cbSize := SizeOf(TLastInputInfo);
    GetLastInputInfo(lii);
    LastInput := lii.dwTime;
  end;

  // show idle tickcount
  Caption := IntToStr(GetTickCount - LastInput);
  Invalidate;

  if LastInput + MAX_APPIDLE_TICKS < GetTickCount
    then Close
    else Done := True;
end;
Getippt und nicht getestet.

Freundliche Grüße
  Mit Zitat antworten Zitat