?
Solved

ScreenSaver Running?

Posted on 2001-08-04
11
Medium Priority
?
493 Views
Last Modified: 2012-05-04
Hello Experts...
I have an app that grabs a screen capture every hour or so, to verify that a certain app is on top...and active..,anyway.
How can I tell if the screensaver is running? (so I can cancel the capture) I need this for all Windows versions, if possible.
Thanks.
0
Comment
Question by:Object_shun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6351957
try this


'**************************************
'Windows API/Global Declarations for :Tu
'     rn off/on screen saver
'**************************************


Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
    Public Const SPI_SETSCREENSAVEACTIVE = 17
    Public Const SPIF_UPDATEINIFILE = &H1
    Public Const SPIF_SENDWININICHANGE = &H2

'

' This routine will turn off the screen
'     saver with a parameter of false
' and switch it back on again with a val
'     ue of true.
' What is particularly interesting is wh
'     en switched off the machine
' Display properties show a screen saver
'     of none but when switched on again
' it remembers the last active screen sa
'     ver.
' I use this routine to switch off the s
'     creen saver when I am doing a lot of
' processing where control is not return
'     ed to the user for a while. It stops
' the screen saver kicking in and lettin
'     g the user think that something has gone
'    
' wrong.


Public Sub StopStartScreenSaver(bFlag As Boolean)
    Dim Result As Long
    Dim ret As Long
    Dim bScreenSaverEnabled As Boolean


    Select Case bFlag
        Case False ' swicth it off
        Call SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0&, ByVal 0&, _
        SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
        Case True' switch it back on
        Call SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1&, ByVal 0&, _
        SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
    End Select
End Sub

hope this will help

andy
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6351958
you could use the code above to turn the screen save off when your code is running.

cheers
Andy
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Object_shun
ID: 6352007
I guess this problem is rather unique....

The MSDN example will tell me when the SCR starts.(WM_SCRNSVSTART)...
but not if it's running. I cant seem to find a WM_SCRNSVSTOP....
I have to let the SCR run...if it is...So I can't shut it down.

Does that make sense....
If I get the WM_SCRNSVSTART hook, well and good, just exit sub....Now I have no way to tell if the SCR is NOT running.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6352271
Hearing...
0
 

Author Comment

by:Object_shun
ID: 6352279
The only thing I can come up with ...to get a list of running apps, and look for a .scr extension.
Seems to be working....but a little "hoggy" for this app.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6352401
Public Const SPI_GETSCREENSAVEACTIVE = 16

I'd guess that it would tell you if a screen saver is running, provided the screen saver itself sets the parameter like it should...
0
 

Author Comment

by:Object_shun
ID: 6353505
SPI_GETSCREENSAVEACTIVE will return true...if they have a screensaver installed, ready to activate...not if it's running.
0
 

Author Comment

by:Object_shun
ID: 6353541
SPI_GETSCREENSAVEACTIVE will return true...if they have a screensaver installed, ready to activate...not if it's running.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6353987
My suggestion:

1. Use GetForegroundWindow to get a handle to the window in front.
2. Use ??? to find out which process the window belongs to.
3. Use ??? to find out what file that process is from.
4. Check that filename for an extension.

You're existing code seems to have numbers 3 and 4 already and maybe even 2. Perhaps you can convert it...
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 400 total points
ID: 6354591
I did a test program:
Option Explicit

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Const SPI_GETSCREENSAVERRUNNING = &H72

Private Sub Form_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Timer1_Timer()
Dim ret As Boolean
SystemParametersInfo SPI_GETSCREENSAVERRUNNING, 0, ret, 0
Text1.Text = ret & vbCrLf & Text1.Text

End Sub


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question