Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#8

AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln

  Alt 4. Jul 2015, 15:25
Folgender Code funktioniert - ob etwas Sinnvolles heraus kommt, weiss ich nicht.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
POWER_INFORMATION_LEVEL =
   (SystemPowerPolicyAc,
    SystemPowerPolicyDc,
    VerifySystemPolicyAc,
    VerifySystemPolicyDc,
    SystemPowerCapabilities,
    SystemBatteryState,
    SystemPowerStateHandler,
    ProcessorStateHandler,
    SystemPowerPolicyCurrent,
    AdministratorPowerPolicy,
    SystemReserveHiberFile,
    ProcessorInformation,
    SystemPowerInformation,
    ProcessorStateHandler2,
    LastWakeTime,
    LastSleepTime,
    SystemExecutionState,
    SystemPowerStateNotifyHandler,
    ProcessorPowerPolicyAc,
    ProcessorPowerPolicyDc,
    VerifyProcessorPowerPolicyAc,
    VerifyProcessorPowerPolicyDc,
    ProcessorPowerPolicyCurrent,
    SystemPowerStateLogging,
    SystemPowerLoggingEntry);


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

type
  NTSTATUS = cardinal;
const
  powrprofdll = 'powrprof.dll';

function CallNtPowerInformation(InformationLevel: POWER_INFORMATION_LEVEL;
  lpInputBuffer: Pointer; nInputBufferSize: cardinal; lpOutputBuffer: Pointer;
  nOutputBufferSize: cardinal): NTSTATUS; stdcall;

function CallNtPowerInformation; external powrprofdll Name 'CallNtPowerInformation';


implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var FLST: Int64;
    FLWT: Int64;
begin

//100-nanosecond units, at the last system wake time
//100-nanosecond units, at the last system sleep time
  CallNtPowerInformation(LastWakeTime,nil,0,@FLWT,SizeOf(FLWT));
  CallNtPowerInformation(LastSleepTime,nil,0,@FLST,SizeOf(FLST));
//wahrscheinlich ist in den folgenden 2 Zeilen etwas falsch

  FLWT:=Round(FLWT/10/1000/60/60); // 100nsec -- 1 msec -- 1sec --1min --1h
  FLST:=Round(FLST/10/1000/60/60); // 100nsec -- 1 msec -- 1sec --1min --1h
  Caption:= INTTOSTR(FLWT - FLST)+' Stunden';
end;

end.

Geändert von hathor ( 4. Jul 2015 um 15:32 Uhr)
  Mit Zitat antworten Zitat