Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IConsolePowerSink::OnPowerBroadcast method

The OnPowerBroadcast method processes WM_POWERBROADCAST notification messages related to the computer's power management.

Syntax


HRESULT OnPowerBroadcast(
  [in]  UINT    nEvent,
  [in]  LPARAM  lParam,
  [out] LRESULT *plReturn
);

Parameters

nEvent [in]

The power broadcast event identifier. The identifier is one of the following values.

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_APMRESUMEAUTOMATIC

Operation resuming automatically after event.

PBT_APMRESUMECRITICAL

Operation resuming after critical suspension.

PBT_APMRESUMESUSPEND

Operation resuming after suspension.

PBT_APMSUSPEND

System is suspending operation.

lParam [in]

Function-specific data. For most events, this parameter is reserved and not used. However, if nEvent is one of the resume events (PBT_APMRESUME*), the lParam parameter can specify the PBTF_APMRESUMEFROMFAILURE flag. This flag indicates that a suspend operation failed after the PBT_APMSUSPEND event was broadcast.

plReturn [out]

On return, the snap-in's response to the broadcast event. Generally, set *plReturn to TRUE. The exception is when nEvent is PBT_APMQUERYSUSPEND. To allow the computer suspension to continue in response to the PBT_APMQUERYSUSPEND event, set *plReturn to TRUE; to deny the computer suspension, set *plReturn to BROADCAST_QUERY_DENY. A snap-in that permits computer suspension should perform necessary suspension preparations before returning from this method.

Return value

If successful, the return value is S_OK. Other return values indicate an error code.

Examples


STDMETHODIMP CConsolePowerSink::OnPowerBroadcast(
    UINT     nEvent,
    LPARAM   lParam,
    LRESULT* plReturn)
{
    if (NULL == plReturn)
        return (E_INVALIDARG);

    switch (nEvent)
    {

    case PBT_APMQUERYSUSPEND:
        // Determine if suspension is OK now and respond
        // appropriately. Be aware that myAppSuspendCheck is 
        // an application-provided function (not shown).
        if (S_OK == myAppSuspendCheck())
        {
            // Take suspension preparation Steps, if required.
            // ...
            // The snap-in grants the suspension request.
            *plReturn = TRUE;
        }
        else
            // The snap-in denies the suspension request.
            *plReturn = BROADCAST_QUERY_DENY;
        break;

    default:
        // The snap-in response is TRUE for all other events.
        *plReturn = TRUE;
        break;
    }

    return (S_OK);
}

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Mmc.h

See also

WM_POWERBROADCAST

 

 

Show: