0
I would like to check windows status (suspended/hibernating) before performing an action.
Example
if suspenso=true then
//executa algo
Thanks in advance.
0
I would like to check windows status (suspended/hibernating) before performing an action.
Example
if suspenso=true then
//executa algo
Thanks in advance.
2
Based on @Guilherme-nascimento’s comment and this article by microsoft I was able to mount an example using the message WM_POWERBROADCAST , which is triggered when windows enters and suspension. The return of the message in the Powerevt property is the current status, where PBT_APMSUSPEND represents that this going into suspension and PBT_APMRESUMEAUTOMATIC represents that this coming out of suspension:
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;
Browser other questions tagged delphi
You are not signed in. Login or sign up in order to post.
Dear @Robertodecampos what AP wants is to know the status of windows and not the app, in case suspended or hibernating.
– Guilherme Nascimento
I didn’t see the title, I’ll remove the comment
– Roberto de Campos
I don’t know how it works with Delphi, but it will probably have to be some kind of "bind" with kernel32 or Powrprof, in this case this function: https://docs.microsoft.com/en-us/windows/desktop/api/Winbase/nf-winbase-getdevicepowerstate - but I’m not sure about it.
– Guilherme Nascimento
Looking better at the microsoft doc the function that will probably suit you is
PowerSettingRegisterNotification
(lib Powrprof), it executes a callback when the energy settings are modified (I think it will have to match with getdevicepowerstate), or else the function that seems to be proper for thisRegisterSuspendResumeNotification
– Guilherme Nascimento