unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
hTimer:THandle;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{function SetSuspendState(
Hibernate: Boolean,
ForceCritical: Boolean,
DisableWakeEvent: Boolean);
{ Parameters:
Hibernate: If this parameter is TRUE, the system hibernates.
If the parameter is FALSE, the system is suspended.
ForceCritical: If this parameter is TRUE, the system suspends operation immediately;
if it is FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to
each application to request permission to suspend operation.
DisableWakeEvent: If this parameter is TRUE, the system disables all wake events.
If the parameter is FALSE, any system wake events remain enabled.
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Included in Windows 98 and later.}
var
_SetSuspendState:
function (Hibernate, ForceCritical, DisableWakeEvent: BOOL): BOOL
stdcall =
nil;
function LinkAPI(
const module, functionname:
string): Pointer;
forward;
function SetSuspendState(Hibernate, ForceCritical,
DisableWakeEvent: Boolean): Boolean;
begin
if not Assigned(_SetSuspendState)
then
@_SetSuspendState := LinkAPI('
POWRPROF.dll', '
SetSuspendState');
if Assigned(_SetSuspendState)
then
Result := _SetSuspendState(Hibernate, ForceCritical,
DisableWakeEvent)
else
Result := False;
end;
function LinkAPI(
const module, functionname:
string): Pointer;
var
hLib: HMODULE;
begin
hLib := GetModulehandle(PChar(module));
if hLib = 0
then
hLib := LoadLibrary(PChar(module));
if hLib <> 0
then
Result := getProcAddress(hLib, PChar(functionname))
else
Result :=
nil;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SetSuspendState(False, True, False);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SetSuspendState(False, False, True);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
liDuTime:LARGE_INTEGER;
weckzeit,uhrzeit:SYSTEMTIME;
ftime:FILETIME;
fitime:FILETIME;
begin
weckzeit.wYear:=0;
weckzeit.wMonth:=0;
weckzeit.wDayOfWeek:=0;
weckzeit.wDay:=0;
weckzeit.wHour:=StrtoInt(Edit1.Text);
weckzeit.wMinute:=StrToInt(Edit2.Text);
weckzeit.wSecond:=0;
weckzeit.wMilliseconds:=0;
SystemTimeToFileTime(weckzeit,ftime);
LocalFileTimeToFileTime(ftime,fitime);
liDuTime.LowPart:=fitime.dwLowDateTime;
liDuTime.HighPart:=fitime.dwHighDateTime;
hTimer:=CreateWaitableTimer(
NIL,true,
NIL);
CancelWaitableTimer(htimer);
SetWaitableTimer(hTimer,lidutime.quadpart,0,
NIL,
NIL,true);
SetSuspendState(true,False,false);
end;
//begin
//SetSuspendState(True, False, False);
//end;
end.