How to wake up from screen/energy -saver from within Delphi application.

How to wake up from screen/energy -saver from within Delphi application.

Post by Dirk » Sun, 05 Dec 2004 08:11:26


Hi,

My application runs on a PC which is constantly ON.
Off course the monitor powers- down automatically after 10 mins. (=Energy
saver)

Now, when some event occurs in my program, I would like to wake up the
monitor automatically.

Before, in Win98, I simply opened another form in my program, and the screen
came on !
Now, in WinXP Pro, this doesn't work anymore.

Thx,
Dirk

PS : Delphi 6
 
 
 

How to wake up from screen/energy -saver from within Delphi application.

Post by Dirk » Sun, 05 Dec 2004 18:54:52

Hi,

My application runs on a PC which is constantly ON.
Off course the monitor powers- down automatically after 10 mins. (=Energy
saver)

Now, when some event occurs in my program, I would like to wake up the
monitor automatically.

Before, in Win98, I simply opened another form in my program, and the screen
came on !
Now, in WinXP Pro, this doesn't work anymore.

Thx,
Dirk

PS : Delphi 6

 
 
 

How to wake up from screen/energy -saver from within Delphi application.

Post by Nicholas S » Mon, 06 Dec 2004 08:02:59

irk B wrote:

Cheap method that may work:

mouse.cursorpos:=point(mouse.cursorpos.x+5,mouse.cursorpos.y+5);
mouse.cursorpos:=point(mouse.cursorpos.x-5,mouse.cursorpos.y-5);

Windows provides SetThreadExecutionState for situations like this.
Here's the article from the Platform SDK, just in case you didn't have it.

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] Thread's execution requirements. This parameter can be one or more
of the following values. Flag Meaning
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.

This function does not always stop the screen saver from executing when
the computer is in use. As an alternative, set a timer and periodically
call the SystemParametersInfo function to query and reset the screen
saver time-out value. (Use the user's default settings in case your
application t
 
 
 

How to wake up from screen/energy -saver from within Delphi application.

Post by Dirk » Wed, 08 Dec 2004 22:13:34

ear Nicholas,

Thanks for the tips. But ...

The mouse trick doesn't work.

I have no experience with Platform SDK functions.
I dont know how to use SetThreadExecutionState.

Could you please explain briefly how to use SetThreadExecutionState in D6 ?

Thx a lot !

Bye

"Nicholas Sherlock" < XXXX@XXXXX.COM > wrote in message
news:cotfn5$mc4$ XXXX@XXXXX.COM ...
(=Energy