SetThreadExecutionState and crash in XP if "Prompt for password..."

K

Kathleen

Hello.

/I am aware that this is not the best group, but I don't really know
where to post that./

Our software needs to "wake up" the monitor. It is achieved by calling

SetThreadExecutionState(ES_DISPLAY_REQUIRED)

...which works OK in most cases, except one: on Windows XP (but not
2000), if the screensaver is protected by password, then
SetThreadExecutionState fails: don't know whether it really returns
zero, simply doesn't wake the monitor, and afterwards the application
fails to respond and throws an exception at exit.

Presently we have added a workaround to this bug, but it is complicated
to explain to customers so we would possibly like to know what we did wrong.

Thank you,


Kathleen

support ta advancedcallmanager tod moc
 
J

Juergen Thuemmler

Our software needs to "wake up" the monitor. It is achieved by calling
SetThreadExecutionState(ES_DISPLAY_REQUIRED)

I'm using
Sub MonitorOnOff(ByVal off&)
Call PostMessageByLong(-1, WM_SYSCOMMAND, SC_MONITORPOWER, IIf(off = 1,
2, -1))
End Sub

It works under XP too.

Juergen.
 
S

Someone

I don't know about the function you are using, but the following code
simulate pressing and releasing the shift key, which obviously has no effect
except ending the screen saver and turn the monitor on if it went to save
mode.


Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan
As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

' In your code
keybd_event vbKeyShift, 0, 0, 0
keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0

As for using the mouse instead, try GetCursorPos/SetCursorPos. Move the
mouse to a different location, then move it back. Don't move it to a fixed
location because the mouse is already there and no movement will occur.
Also, don't use x+1, or y+1, because the mouse could be at the end of the
screen. Make sure that your logic will move the mouse. I haven't used this
method so I am not sure if it going to work.

Finally, I think there is a function out there that tells the screen saver
to stop, but I am not sure if any exist, nor if it wakes up the monitor.
 
K

Kathleen

Someone said:
I don't know about the function you are using, but the following code
simulate pressing and releasing the shift key, which obviously has no effect
except ending the screen saver and turn the monitor on if it went to save
mode.

Thank you, I will try it.
[...]
As for using the mouse instead, try GetCursorPos/SetCursorPos. Move the
mouse to a different location, then move it back.

Doesn't work, that's what I tried first. The key trick may work though.
Don't move it to a fixed
location because the mouse is already there and no movement will occur.
Also, don't use x+1, or y+1, because the mouse could be at the end of the
screen. Make sure that your logic will move the mouse. I haven't used this
method so I am not sure if it going to work.

Finally, I think there is a function out there that tells the screen saver
to stop, but I am not sure if any exist, nor if it wakes up the monitor.

It's the above one ;)

Kathleen.
 
T

Tony Spratt

As for using the mouse instead, try GetCursorPos/SetCursorPos. Move the
Doesn't work, that's what I tried first. The key trick may work though.

Most screensavers/sleep routines will ignore single-jump mouse moves - these
can occur at random without the mouse actually being moved, referred to as
"artefact mouse movement", I believe. What I do know about these artefact
movements is that when I wrote my first screensaver it took me about two
days to figure out why it kept slef-cancelling after a few seconds... <g>

To use the mouse-move method, have the mouse jump out and then back with a
gap in between - say, 100th of a second. That should do the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top