To know when OS goes into screen saver

R

Rob

Is there a way that VB can know when the operating system
goes into screen save mode? I have continuous polling I
wish to pause while in screen save mode. And likewise to
wake back up when the screen saver is turned back off.

Any help on this will be greatly appreciated.

Rob
 
T

Tom Shelton

Rob said:
Is there a way that VB can know when the operating system
goes into screen save mode? I have continuous polling I
wish to pause while in screen save mode. And likewise to
wake back up when the screen saver is turned back off.

Any help on this will be greatly appreciated.

Rob

You can use SystemParametersInfo with the SPI_GETSCREENSAVERRUNNING flag
to find out if the screen saver is running... In other words, you could
have a timer that fires every second or so and calls this function. If
it's running put your worker thread to sleep. If it's not, wake it up...

HTH,
Tom Shelton
 
F

Fergus Cooney

Hi Rob,

Certain Windows events can be waited on, eg system shutdown, display
properties changes, etc.(see the SystemEvents class). Unfortunately there's no
mention of any Windows event occurring when the screen saver starts.

The following is a VB (classic) project which detects whether a
workstation is locked or not. It include some very straightforward code to
detect whether the screen saver is running, but you'll have to keep checking.

http://www.mvps.org/st-software/Code/DetectLockedWorkstation.zip

Regards,
Fergus
 
A

Armin Zingler

Rob said:
Is there a way that VB can know when the operating system
goes into screen save mode? I have continuous polling I
wish to pause while in screen save mode. And likewise to
wake back up when the screen saver is turned back off.

Any help on this will be greatly appreciated.

Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)

Const WM_SYSCOMMAND As Integer = &H112
Const SC_SCREENSAVE As Integer = &HF140

MyBase.WndProc(m)

If m.Msg = WM_SYSCOMMAND _
AndAlso m.WParam.ToInt32 = SC_SCREENSAVE Then

Debug.WriteLine("Screensaver activated")
End If
End Sub
 
T

Tom Shelton

Armin said:
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)

Const WM_SYSCOMMAND As Integer = &H112
Const SC_SCREENSAVE As Integer = &HF140

MyBase.WndProc(m)

If m.Msg = WM_SYSCOMMAND _
AndAlso m.WParam.ToInt32 = SC_SCREENSAVE Then

Debug.WriteLine("Screensaver activated")
End If
End Sub

Well, I'll be... You learn something new every day. That is going down
in my little book of knowledge...

Tom Shelton
 
R

Rob

Thank you Armin. That looks very straight forward. Is
there a listing anywhere of these great little Windows
Message constants?

Rob
 
A

Armin Zingler

Tom Shelton said:
Well, I'll be... You learn something new every day. That is going
down in my little book of knowledge...

:)

Unfortunately, I don't know how to detect when the screen saver is closed.
:)
 
A

Armin Zingler

Rob said:
Thank you Armin. That looks very straight forward. Is
there a listing anywhere of these great little Windows
Message constants?


Press <F1> and select "MSDN library". ;-)


In this case, I added
Debug.WriteLine(m)
to Sub WndProc, waited for the screen saver to be started and found out that
WM_SYSCOMMAND is sent. In the help index, after pasting "WM_SYSCOMMAND" you
get the message documentation.
 
T

Tom Shelton

Armin said:
:)

Unfortunately, I don't know how to detect when the screen saver is closed.
:)

Well, then... I guess that does put a damper on things :) Using the
SystemParametersInfo - you can find out...

Tom Shelton
 
T

Tom Spink

Write a DLL that injects itself into the CreateProcess API and detect which
process is created when the screensaver comes active... Then, wait until the
process has terminated and therefore the screen saver has closed.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: > > Protected Overrides Sub WndProc( _
: > > ByRef m As System.Windows.Forms.Message)
: > >
: > > Const WM_SYSCOMMAND As Integer = &H112
: > > Const SC_SCREENSAVE As Integer = &HF140
: > >
: > > MyBase.WndProc(m)
: > >
: > > If m.Msg = WM_SYSCOMMAND _
: > > AndAlso m.WParam.ToInt32 = SC_SCREENSAVE Then
: > >
: > > Debug.WriteLine("Screensaver activated")
: > > End If
: > > End Sub
: > >
: > >
: >
: > Well, I'll be... You learn something new every day. That is going
: > down in my little book of knowledge...
:
: :)
:
: Unfortunately, I don't know how to detect when the screen saver is closed.
: :)
:
:
: --
: Armin
:
 

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