Valhalla Legends Forums Archive | General Programming | API Call for Putting Monitor into Sleep Mode

AuthorMessageTime
Necrosis
Anyone have the API call for putting your monitor to sleep on an NT based system in Visual Basic? Call and usage if possible..thx

Necrosis
December 29, 2002, 10:12 PM
Etheran
If my keyboard can do it I'm sure it can't be hard.  ;D
December 30, 2002, 9:27 AM
Skywing
I think this is what you're looking for.  There are a variety of other power management things you can set; see "Power Management Functions" in MSDN.  It shouldn't be too hard for you to translate the function prototype to VB.
[quote]
SetSuspendState
The SetSuspendState function suspends the system by shutting power down. Depending on the Hibernate parameter, the system either enters a suspend (sleep) state or hibernation (S4). If the ForceFlag parameter is TRUE, the system suspends operation immediately; if it is FALSE, the system requests permission from all applications and device drivers before doing so.

BOOL SetSuspendState (
 BOOL Hibernate,
 BOOL ForceCritical,
 BOOL DisableWakeEvent
);
Parameters
Hibernate
[in] Specifies the state of the system. If TRUE, the system hibernates. If FALSE, the system is suspended.
ForceCritical
[in] Forced suspension. If TRUE, the function broadcasts a PBT_APMSUSPEND event to each application and driver, then immediately suspends operation. If FALSE, the function broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation.
DisableWakeEvent
[in] If TRUE, the system disables all wake events. If FALSE, any system wake events remain enabled.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
An application may use SetSuspendState to transition the system from the working state to the standby (sleep), or optionally, hibernate (S4) state. This function is similar to the SetSystemPowerState function.

Requirements
 Windows NT/2000/XP: Included in Windows 2000 and later.
 Windows 95/98/Me: Included in Windows 98 and later.
 Header: Declared in Powrprof.h.
 Library: Use Powrprof.lib.

See Also
Power Management Overview, Power Management Functions, PBT_APMQUERYSUSPEND, PBT_APMSUSPEND
[/quote]
There's also a less-powerful, Win95-compatible version:
[quote]
SetSystemPowerState
The SetSystemPowerState function suspends the system by shutting power down. Depending on the ForceFlag parameter, the function either suspends operation immediately or requests permission from all applications and device drivers before doing so.

The calling process must have the SE_SHUTDOWN_NAME privilege. To enable the SE_SHUTDOWN_NAME privilege, use the AdjustTokenPrivileges function. For more information, see Privileges.

BOOL SetSystemPowerState(
 BOOL fSuspend,
 BOOL fForce
);
Parameters
fSuspend
Windows NT/2000/XP: [in] Specifies the state of the system. If TRUE, the system is suspended. If FALSE, the system hibernates.
Windows 95/98/Me: Ignored.

fForce
[in] Forced suspension. If TRUE, the function broadcasts a PBT_APMSUSPEND event to each application and driver, then immediately suspends operation. If FALSE, the function broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation.
Return Values
If power has been suspended and subsequently restored, the return value is nonzero.

If the system was not suspended, the return value is zero. To get extended error information, call GetLastError.

Remarks
If any application or driver denies permission to suspend operation, the function broadcasts a PBT_APMQUERYSUSPENDFAILED event to each application and driver. If power is suspended, this function returns only after system operation is resumes and related WM_POWERBROADCAST messages have been broadcast to all applications and drivers.

This function is similar to the SetSuspendState function.

Requirements
 Windows NT/2000/XP: Included in Windows 2000 and later.
 Windows 95/98/Me: Included in Windows 95 and later.
 Header: Declared in Winbase.h; include Windows.h.
 Library: Use Kernel32.lib.

See Also
Power Management Overview, Power Management Functions, PBT_APMQUERYSUSPEND, PBT_APMQUERYSUSPENDFAILED, PBT_APMSUSPEND, SetSuspendState, WM_POWERBROADCAST
[/quote]

Continuing with the next message due to YaBB limitations...
December 30, 2002, 12:33 PM
Skywing
You can change the idle time before the display is switched off with the following function:
[quote]
WritePwrScheme
The WritePwrScheme function writes policy settings that are unique to the specified power scheme.

BOOL WritePwrScheme (
 PUINT puiID,
 LPTSTR lpszName,
 LPTSTR lpszDescription,
 PPOWER_POLICY pPowerPolicy
);
Parameters
puiID
[in] Index of the power scheme to be written. If a power scheme with the same index already exists, it is replaced. Otherwise, a new power scheme is created.
lpszName
[in] Pointer to a null-terminated string that specifies the name of the power scheme.
lpszDescription
[in] Pointer to a null-terminated string that specifies the description of the power scheme.
pPowerPolicy
[in] Pointer to a POWER_POLICY structure that contains the power policy settings to be written.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
This change does not affect the current system power policy. To apply this change to the current system power policy, call the SetActivePwrScheme function with the index of this power scheme.

Power policy schemes written using WritePwrScheme are permanently stored in the system registry hives, and remain available for use in the Power Options control panel program, or by subsequent calls to the power scheme API. To permanently remove a power scheme from the system, call the DeletePwrScheme function.

Requirements
 Windows NT/2000/XP: Included in Windows 2000 and later.
 Windows 95/98/Me: Included in Windows 98 and later.
 Header: Declared in Powrprof.h.
 Library: Use Powrprof.lib.

See Also
Power Management Overview, Power Management Functions, DeletePwrScheme, POWER_POLICY, ReadPwrScheme, SetActivePwrScheme
[/quote]
December 30, 2002, 12:49 PM

Search