Solved

ScreenSaver Running?

Posted on 2001-08-04
11
488 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
  • 4
  • 2
  • 2
  • +2
11 Comments
 

Expert Comment

by:Alon_h
ID: 6351956
0
 
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

816 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now