Solved

ScreenSaver Running?

Posted on 2001-08-04
11
492 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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 100 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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