Solved

ScreenSaver Running?

Posted on 2001-08-04
11
486 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now