Look up "Power Messages" in the Windows SDK (under the help menu).
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
The system sends power messages to all applications and installable drivers whenever a power management event occurs or whenever an application calls the SetSystemPowerState function to suspend operation. The system sends these messages through the WM_POWERBROADCAST message, setting the wParam
parameter to the message type. For example, the message type, PBT_APMPOWERSTATUSCHANGE, indicates a system power status change message.
The system sends a PBT_APMQUERYSUSPEND message to request permission to suspend system operation. The system expects each application and driver to determine whether the requested event should occur and to return TRUE or BROADCAST_QUERY_DENY indicating this decision. Any application or driver can deny the request and prevent it from occurring.
The system sends a PBT_APMSUSPEND message immediately before suspending operation. This gives applications and drivers one last chance to prepare for the event before it occurs. In many cases, the system sends these messages without requesting permission to do so. This happens, for example, if an application forces suspension with the SetSystemPowerState function.
The system sends the PBT_APMQUERYSUSPENDFAILED message whenever a requested event is denied. These messages are intended to notify applications and drivers to continue operation as usual.
The system sends the PBT_APMRESUMESUSPEND or PBT_APMRESUMECRITICAL message when system operation has been restored.
Note The WM_POWER message, previously available to applications and drivers for use with power management, is maintained for backward compatibility. All current applications and installable drivers should use and process the WM_POWERBROADCAST message instead.
//----------------------------------------
WM_PowerBroadcast Help
The WM_POWERBROADCAST message is sent to an application to notify it of power-management events.
Event notification message. This parameter can be one of the following values:
Value Meaning
PBT_APMBATTERYLOW Battery power is low.
PBT_APMOEMEVENT OEM-defined event occurred.
PBT_APMPOWERSTATUSCHANGE Power status has changed.
PBT_APMQUERYSUSPEND Request for permission to suspend.
PBT_APMQUERYSUSPENDFAILED Suspension request denied.
PBT_APMRESUMECRITICAL Operation resuming after critical suspension.
PBT_APMRESUMESUSPEND Operation resuming after suspension.
PBT_APMSUSPEND System is suspending operation.
dwData
Function-specific data. For most messages, this parameter is reserved and not used.
However, if wParam is one of the resume notifications (PBT_APMRESUME*), the lParam parameter can specify the PBTF_APMRESUMEFROMFAILURE flag. This flag indicates that a suspend operation failed after the PBT_APMSUSPEND message was sent.
Return Values
Return TRUE to grant a request.
Return BROADCAST_QUERY_DENY to deny a request.
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
although, with which procedure can I catch this message?
I tried with :
procedure TfrmLoc.FormMessage(var Msg: TMsg; var Handled: Boolean);
begin
msg.
Case msg.Message of
WM_KEYFIRST..WM_KEYLAST, WM_MOUSEFIRST..WM_MOUSELAST:
Timer.Enabled := False;
WM_POWERBROADCAST:
begin
DataModule2.DataModuleDestroy(nil);
Application.Terminate;
end;
end;
end;
Are you trying to catch this on the main form, or a secondary form?
What if you try using the TApplicationEvents component (on the "additional" tab of the palette)?
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.