How to capture windows status (suspend / hibernate) via Delphi code

0

I would like to check the status of windows (suspend / hibernate) before performing an action.

Example

if suspenso=true then
   //executa algo

Thank you in advance.

    
asked by anonymous 23.08.2018 / 22:06

1 answer

2

Based on the @ Guilherme-natal comment and this microsoft article > I was able to set up an example using the WM_POWERBROADCAST message, which is triggered the moment windows enter and suspend. The return of the message in the PowerEvt property is the current status, where PBT_APMSUSPEND represents that it is suspending and PBT_APMRESUMEAUTOMATIC represents that it is leaving the suspend:

  TForm1 = class(TForm)
  private
    fSuspenso: Boolean;
    procedure AlterouStatusDoWindows(var Msg: TWMPower); message WM_POWERBROADCAST;
  public
  end;

...
procedure TForm1.AlterouStatusDoWindows(var Msg: TWMPower);
begin
  case MSg.PowerEvt of
    PBT_APMSUSPEND: fSuspenso := True;
    PBT_APMRESUMEAUTOMATIC: fSuspenso := False;
  end;
end;
    
28.08.2018 / 22:06