2
I have a system that works with websocket in Delphi with mORMot, when I restart the PC or when I disconnect it runs Onclose and Ondestroy and through that I can remove the callback of the logged in user, but when I have hibernate or suspend I need to do the same so that the user is not listed as logged in.
It would be good also to warn the user that the system will be closed before it restarts/shutdown or suspend/hibernate and if possible I identify that the computer is coming back from suspension/hibernation to be able to register it again.
I found this example but could not understand its functioning and how it is called:
Statement:
private
procedure Hiber(var pMsg: TWMPower); message WM_POWERBROADCAST;
Implementation:
procedure Tform.Hiber(var pMsg: TWMPower);
begin
if (pMsg.PowerEvt = PBT_APMQUERYSUSPEND) then
begin
// Hibernando
end
else if (pMsg.PowerEvt = PBT_APMRESUMESUSPEND) then
begin
// Retornando
end;
pMsg.result := 1;
end;
Dude, I’m gonna give it a try there, but it looks like it’s messing with notifications/messages from windows itself. I usually use this type of methods in threads when I need to make visual changes. This code works for you ?
– Victor Tadashi
I don’t know what this procedure would be called. I couldn’t run it. But it would be something like this anyway. When it hibernates I remove the callback, when it comes back I log again.
– Wendel Rodrigues
Check this out: https://github.com/xn-nding-jua/PC_DIMMMER/blob/master/Core/PowerButton.pas
– Reginaldo Rigo
I’m not understanding what this procedure is calling.
– Wendel Rodrigues
Using the example you posted: you declare to the operating system that when there is a message of type
WM_POWERBROADCAST
he should call the trialHiber
of your application. This precedent should be created with the parameters required by the call. This is recorded in a system table that takes care of calling it every time such an event occurs.– Reginaldo Rigo
That code I posted is not working here. I had found at this link: http://www.scriptbrasil.com.br/forum/topic/86661-hiberna%C3%A7%C3%A3o/
– Wendel Rodrigues