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
Solved

ScreenSaver Running?

Posted on 2001-08-04
11
490 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

828 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