heyaaa =D
Ich hab einen
Windows Dienst programmiert (mit der von Delphi gegeben Komponente "
Service-Anwendung").
Allerdings lässt sich damit der Ruhezustand nicht abfragen!
Folgender Code funktioniert bei einer
normalen Form1:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm1 = class(TForm) private public procedure WMPowerBroadcast(var Msg: TMessage); message WM_POWERBROADCAST; end;
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;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMPowerBroadcast(var Msg: TMessage); begin showmessage('PowerBroadcast erhalten'); if (Msg.WParam = PBT_APMSUSPEND) or (Msg.WParam = PBT_APMSTANDBY) then begin showmessage('Standby/Ruhezustand'); Msg.Result := 1; end else if (Msg.WParam = PBT_APMRESUMECRITICAL) or (Msg.WParam = PBT_APMRESUMESUSPEND) or (Msg.WParam = PBT_APMRESUMESTANDBY) then begin showmessage('Rückkehr aus Standby/Ruhezustand'); end; end;
end. |
Allerdings nicht in der Service Komponente! Er bringt zwar beim kompilieren keinen Fehler. Allerdings bekommt er auch nicht mit, dass der PC in den Ruhezustand geht.