Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sleep mode in delphi 1

Status
Not open for further replies.

neotropic

Programmer
Feb 17, 2004
13
CA
Hi all,

is there any way to catch the computer sleep mode event with an application created in Delphi 7 ?

cheers,

Julien
 
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
 
Hi,

I didn't found documentation about power messages in my windows help...

I tried to do something with this procedure :

private
procedure WMSysCommand (var Msg: TWMSysCommand);
message WM_SYSCOMMAND;

procedure TfrmLoc.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.cmdType = SC_ScreenSave then
Msg.Result := -1;
else
inherited
end;


And nothing works...the event isn't catch.
The problem is that I have to close 2 ADO connections before the sleep mode event.

Anybody has a clue?

julien
 
You can go to and search or go to:


or


From Delphi Help:

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.

dwPowerEvent = (DWORD) wParam;
dwData = (DWORD) lParam;


Parameters

dwPowerEvent

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
 
Thanx man, really helpful..

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;

but nothing happened...

cheers

julien

 
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
 
I want to catch the event on my main form.

The component TApplicationEvents acts exactly like my procedure, so there is no changes.

My procedure catches other events like mouse clicks or activation for example, but not the system events.

Thanx for your help!

Julien
 
There's the message number 512 that is catch before the sleep mode event but I can't find it's constant name (like WM_SYSCOMMAND for example).

I don't know if this could be the message...

Cheers,

Julien
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top