unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jwawinbase, JwaWinNT;
type
TForm1 =
class(TForm)
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
procedure WMPowerBroadcast(
var MyMessage: TMessage);
message WM_POWERBROADCAST;
end;
var
Form1: TForm1;
const
PBT_APMQUERYSUSPEND = $0000;
PBT_APMQUERYSTANDBY = $0001;
PBT_APMQUERYSUSPENDFAILED = $0002;
PBT_APMQUERYSTANDBYFAILED = $0003;
PBT_APMSUSPEND = $0004;
PBT_APMSTANDBY = $0005;
PBT_APMRESUMECRITICAL = $0006;
PBT_APMRESUMESUSPEND = $0007;
PBT_APMRESUMESTANDBY = $0008;
PBTF_APMRESUMEFROMFAILURE = $00000001;
PBT_APMBATTERYLOW = $0009;
PBT_APMPOWERSTATUSCHANGE = $000A;
PBT_POWERSETTINGCHANGE = $8013;
PBT_APMOEMEVENT = $000B;
PBT_APMRESUMEAUTOMATIC = $0012;
implementation
{$R *.dfm}
procedure TForm1.WMPowerBroadcast(
var MyMessage: TMessage);
begin
if MyMessage.Msg = WM_POWERBROADCAST
then begin
if (MyMessage.WParam = PBT_APMQUERYSUSPEND)
or (MyMessage.WParam = PBT_APMQUERYSTANDBY)
then begin
// windows wants to go into standby or hibernation mode
// Hier hin, was getan werden muss, bevor Windows in den Standby darf,
// z.B. Netzwerk- oder Datenbankverbindungen trennen, Timer abstellen, etc.
MyMessage.Result := 1;
// allow standby/hibernation
// MyMessage.Result := BROADCAST_QUERY_DENY; // deny standby/hibernation
end else if (MyMessage.WParam = PBT_APMRESUMEAUTOMATIC)
or (MyMessage.WParam = PBT_APMRESUMECRITICAL)
or
(MyMessage.WParam = PBT_APMRESUMESUSPEND)
or (MyMessage.WParam = PBT_APMRESUMESTANDBY)
then begin
// windows returns from standby or hibernation
// Hier z.B. Verbindungen wiederherstellen
// und Windows sagen das es benötigt wird und sich nicht automatisch ohne Usereingabe wieder ausschaltet
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
SetThreadExecutionState(ES_CONTINUOUS);
end;
end;
end;
end.