unit FormMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,
GetWindowsVersion;
type
TfrmMain =
class(TForm)
MemoMessageLog: TMemo;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMPowerBroadcast(
var MyMessage: TMessage);
message WM_POWERBROADCAST;
end;
var
frmMain: TfrmMain;
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_APMOEMEVENT = $000B;
PBT_APMRESUMEAUTOMATIC = $0012;
implementation
{$R *.dfm}
{ TfrmMain }
function TranslatePowerBroadcast(
const Msg: Cardinal):
string;
begin
case Msg
of
WM_POWERBROADCAST: Result := '
WM_POWERBROADCAST';
PBT_APMQUERYSUSPEND: Result := '
PBT_APMQUERYSUSPEND';
PBT_APMQUERYSTANDBY: Result := '
PBT_APMQUERYSTANDBY';
PBT_APMQUERYSUSPENDFAILED: Result := '
PBT_APMQUERYSUSPENDFAILED';
PBT_APMQUERYSTANDBYFAILED: Result := '
PBT_APMQUERYSTANDBYFAILED';
PBT_APMSUSPEND: Result := '
PBT_APMSUSPEND';
PBT_APMSTANDBY: Result := '
PBT_APMSTANDBY';
PBT_APMRESUMECRITICAL: Result := '
PBT_APMRESUMECRITICAL';
PBT_APMRESUMESUSPEND: Result := '
PBT_APMRESUMESUSPEND';
PBT_APMRESUMESTANDBY: Result := '
PBT_APMRESUMESTANDBY';
//PBTF_APMRESUMEFROMFAILURE: Result := 'PBTF_APMRESUMEFROMFAILURE';
PBT_APMBATTERYLOW: Result := '
PBT_APMBATTERYLOW';
PBT_APMPOWERSTATUSCHANGE: Result := '
PBT_APMPOWERSTATUSCHANGE';
PBT_APMOEMEVENT: Result := '
PBT_APMOEMEVENT';
PBT_APMRESUMEAUTOMATIC: Result := '
PBT_APMRESUMEAUTOMATIC';
else
Result := '
Unknown Message "'+IntToStr(Msg)+'
"';
end;
end;
procedure TfrmMain.WMPowerBroadcast(
var MyMessage: TMessage);
begin
if MyMessage.Msg = WM_POWERBROADCAST
then begin
MemoMessageLog.Lines.Append('
Msg: '+TranslatePowerBroadcast(MyMessage.Msg));
MemoMessageLog.Lines.Append('
WParam: '+TranslatePowerBroadcast(MyMessage.WParam));
MemoMessageLog.Lines.Append('
');
MemoMessageLog.Lines.SaveToFile(ExtractFileDir(Application.ExeName)+'
\Message.log');
// windows powermanagement message
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_APMRESUMECRITICAL)
or
(MyMessage.WParam = PBT_APMRESUMESUSPEND)
or
(MyMessage.WParam = PBT_APMRESUMESTANDBY)
then begin
// windows returns from standby or hibernation
// Hier z.B. Verbindungen wiederherstellen
end;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
MemoMessageLog.Lines.Append('
Running on:');
MemoMessageLog.Lines.Append(GetWinVersion);
MemoMessageLog.Lines.Append('
');
end;
end.