Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32 API to keep display from going to sleep

56 views
Skip to first unread message

Robert Solomon

unread,
May 11, 2003, 9:22:58 PM5/11/03
to
Hi. I interested in finding out if there is an API for Win32 that will
prevent the Windows display inactivity timer from going to sleep. Or is
there an API that will reset this timer programmatically?

Thanks,
Rob

David Candy

unread,
May 11, 2003, 9:57:57 PM5/11/03
to
SetThreadExecutionState
The SetThreadExecutionState function enables applications to inform the system that it is in use, thereby preventing the system from entering the sleeping power state while the application is running.

EXECUTION_STATE SetThreadExecutionState(
EXECUTION_STATE esFlags
);
Parameters
esFlags
[in] Specifies the thread's execution requirements. This parameter can be one or more of the following values. Flag Description
ES_SYSTEM_REQUIRED Informs the system that the thread is performing some operation that is not normally detected as activity by the system.
ES_DISPLAY_REQUIRED Informs the system that the thread is performing some operation that is not normally detected as display activity by the system.
ES_USER_PRESENT Informs the system that a user is present. If a user is present, the system will use the power policy settings set by the user. Otherwise, the system does not wake the display device and will return to the sleeping state as soon as possible.
ES_CONTINUOUS Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.


Return Values
If the function succeeds, the return value is the previous thread execution state.

If the function fails, the return value is NULL.

Remarks
Activities that are automatically detected include local keyboard or mouse input, server activity, and changing window focus. Activities that are not automatically detected include disk or CPU activity and video display.

Calling SetThreadExecutionState with ES_SYSTEM_REQUIRED prevents the system from putting the computer in the sleeping state by resetting the system idle timer. Calling SetThreadExecutionState with ES_DISPLAY_REQUIRED prevents the system from turning off the display by resetting the display idle timer. Calling SetThreadExecutionState without ES_CONTINUOUS simply resets the idle timer; to keep the display or system in the working state, the thread must call SetThreadExecutionState periodically.

To run properly on a power-managed computer, applications such as fax servers, answering machines, backup agents, and network management applications must use ES_SYSTEM_REQUIRED | ES_CONTINUOUS when they process events. Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input. Applications such as word processors, spreadsheets, browsers, and games do not need to call SetThreadExecutionState.

The SetThreadExecutionState function cannot be used to prevent the user from putting the computer in standby mode. To prevent the user from putting the computer in standby mode, the application must deny the PBT_APMQUERYSUSPEND event.

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

See Also
Power Management Overview, Power Management Functions, SetSystemPowerState, WM_POWERBROADCAST


Platform SDK Release: August 2001 What did you think of this topic?
Let us know. Order a Platform SDK CD Online
(U.S/Canada) (International)

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

See Also
Power Management Overview, Power Management Functions, SetSystemPowerState, WM_POWERBROADCAST


--
http://www.g2mil.com/Apr2003.htm
http://prorev.com/forbesrussia.htm
---------------------------------------------------------------
David Candy
http://www.mvps.org/serenitymacros
---------------------------------------------------------------
"Robert Solomon" <r...@drrob1.com> wrote in message news:MPG.1928c1893...@news-server.optonline.net...

tiny.gif
sendfdbk.gif
download.gif
0 new messages