DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Screensaver running? What's wrong?

  1. #1
    David Crowell Guest

    Screensaver running? What's wrong?

    I'm using the following code on Win98SE, but it always returns False. Any
    ideas?

    btw... if I replace Call with debug.print it returns 1 which according to
    MSDN:
    <quote>
    Return Values
    If the function succeeds, the return value is a nonzero value.

    If the function fails, the return value is zero. To get extended error
    information, call GetLastError.
    </quote>

    So I get no error indication, yet it still returns false when the screen
    saver is running.

    Thanks,
    David



    Private Const SPI_GETSCREENSAVERRUNNING = 97&
    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

    Private Function ScreenSaverRunning() As Boolean

    Dim t As Long
    Dim r As Long
    Call SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    t = Err.LastDllError
    Debug.Print t, r ' always returns 0,0
    If t <> 0 Then Exit Function
    ScreenSaverRunning = Not (r = 0)

    End Function




  2. #2
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    Try using:

    t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)

    And see if this works. I do not think the LastDllError is what you want.

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>

    > Private Function ScreenSaverRunning() As Boolean
    >
    > Dim t As Long
    > Dim r As Long
    > Call SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > t = Err.LastDllError
    > Debug.Print t, r ' always returns 0,0
    > If t <> 0 Then Exit Function
    > ScreenSaverRunning = Not (r = 0)
    >
    > End Function
    >
    >
    >




  3. #3
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    Try using:

    t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)

    And see if this works. I do not think the LastDllError is what you want.

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>

    > Private Function ScreenSaverRunning() As Boolean
    >
    > Dim t As Long
    > Dim r As Long
    > Call SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > t = Err.LastDllError
    > Debug.Print t, r ' always returns 0,0
    > If t <> 0 Then Exit Function
    > ScreenSaverRunning = Not (r = 0)
    >
    > End Function
    >
    >
    >




  4. #4
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    Eric D. Burdo <vbtips@redleif.com> wrote in message
    news:38e37a6d@news.devx.com...
    > Try using:
    >
    > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    >
    > And see if this works. I do not think the LastDllError is what you want.


    I modified it to:

    Private Function ScreenSaverRunning() As Boolean

    Dim t As Long
    Dim r As Long
    t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    If t = 0 Then Exit Function
    ScreenSaverRunning = Not (r = 0)

    End Function

    with no effect. I'm still completely at a loss.

    Dave




  5. #5
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    Eric D. Burdo <vbtips@redleif.com> wrote in message
    news:38e37a6d@news.devx.com...
    > Try using:
    >
    > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    >
    > And see if this works. I do not think the LastDllError is what you want.


    I modified it to:

    Private Function ScreenSaverRunning() As Boolean

    Dim t As Long
    Dim r As Long
    t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    If t = 0 Then Exit Function
    ScreenSaverRunning = Not (r = 0)

    End Function

    with no effect. I'm still completely at a loss.

    Dave




  6. #6
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    Are you using Win9x or Win2k? According to a post I just read on Deja, the
    SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    incorrect in stating that it works on Win98.

    You could try this code (again, I got this from a post on Deja)

    Option Explicit

    Private Const SPI_SCREENSAVERRUNNING = 97
    Private Declare Function SystemParametersInfoSS _
    Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long,
    ByVal uParam As Long, _
    ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

    Private Sub Form_Load()
    Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Timer()
    If SSRunning Then Me.Caption = "SS"
    End Sub

    Private Function SSRunning() As Boolean
    Dim lRetVal As Long
    Dim lRunning As Long
    On Error Resume Next
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    0&)
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    0&)
    If lRunning <> 0 Then
    SSRunning = True
    End If
    End Function

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>


    "David Crowell" <davidc@qtm.net> wrote in message
    news:38e38a97@news.devx.com...
    >
    > Eric D. Burdo <vbtips@redleif.com> wrote in message
    > news:38e37a6d@news.devx.com...
    > > Try using:
    > >
    > > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > >
    > > And see if this works. I do not think the LastDllError is what you

    want.
    >
    > I modified it to:
    >
    > Private Function ScreenSaverRunning() As Boolean
    >
    > Dim t As Long
    > Dim r As Long
    > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > If t = 0 Then Exit Function
    > ScreenSaverRunning = Not (r = 0)
    >
    > End Function
    >
    > with no effect. I'm still completely at a loss.
    >
    > Dave
    >
    >
    >




  7. #7
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    Are you using Win9x or Win2k? According to a post I just read on Deja, the
    SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    incorrect in stating that it works on Win98.

    You could try this code (again, I got this from a post on Deja)

    Option Explicit

    Private Const SPI_SCREENSAVERRUNNING = 97
    Private Declare Function SystemParametersInfoSS _
    Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long,
    ByVal uParam As Long, _
    ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

    Private Sub Form_Load()
    Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Timer()
    If SSRunning Then Me.Caption = "SS"
    End Sub

    Private Function SSRunning() As Boolean
    Dim lRetVal As Long
    Dim lRunning As Long
    On Error Resume Next
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    0&)
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    0&)
    If lRunning <> 0 Then
    SSRunning = True
    End If
    End Function

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>


    "David Crowell" <davidc@qtm.net> wrote in message
    news:38e38a97@news.devx.com...
    >
    > Eric D. Burdo <vbtips@redleif.com> wrote in message
    > news:38e37a6d@news.devx.com...
    > > Try using:
    > >
    > > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > >
    > > And see if this works. I do not think the LastDllError is what you

    want.
    >
    > I modified it to:
    >
    > Private Function ScreenSaverRunning() As Boolean
    >
    > Dim t As Long
    > Dim r As Long
    > t = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, r, 0)
    > If t = 0 Then Exit Function
    > ScreenSaverRunning = Not (r = 0)
    >
    > End Function
    >
    > with no effect. I'm still completely at a loss.
    >
    > Dave
    >
    >
    >




  8. #8
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    > Are you using Win9x or Win2k? According to a post I just read on Deja,

    the
    > SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    > incorrect in stating that it works on Win98.


    That's not good. I installed 98 over 95 just so I could do this...
    I looked on the online version of MSDN and noticed that it is still listed
    for Win98 & 2000.

    <code snipped>

    I tried that code, it still returns false. Do you know of any official word
    from MS that this doesn't work? I did search MSDN (again)

    Thanks,
    Dave




  9. #9
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    > Are you using Win9x or Win2k? According to a post I just read on Deja,

    the
    > SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    > incorrect in stating that it works on Win98.


    That's not good. I installed 98 over 95 just so I could do this...
    I looked on the online version of MSDN and noticed that it is still listed
    for Win98 & 2000.

    <code snipped>

    I tried that code, it still returns false. Do you know of any official word
    from MS that this doesn't work? I did search MSDN (again)

    Thanks,
    Dave




  10. #10
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    No, no official word. Just two or three posts from Deja that I cam across.

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>


    "David Crowell" <davidc@qtm.net> wrote in message
    news:38e3d3bc$1@news.devx.com...
    >
    > > Are you using Win9x or Win2k? According to a post I just read on Deja,

    > the
    > > SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    > > incorrect in stating that it works on Win98.

    >
    > That's not good. I installed 98 over 95 just so I could do this...
    > I looked on the online version of MSDN and noticed that it is still listed
    > for Win98 & 2000.
    >
    > <code snipped>
    >
    > I tried that code, it still returns false. Do you know of any official

    word
    > from MS that this doesn't work? I did search MSDN (again)
    >
    > Thanks,
    > Dave
    >
    >
    >




  11. #11
    Eric D. Burdo Guest

    Re: Screensaver running? What's wrong?

    No, no official word. Just two or three posts from Deja that I cam across.

    --

    Eric D. Burdo, Red-Leif International
    VB Programmer and Consultant
    <http://www.redleif.com>


    "David Crowell" <davidc@qtm.net> wrote in message
    news:38e3d3bc$1@news.devx.com...
    >
    > > Are you using Win9x or Win2k? According to a post I just read on Deja,

    > the
    > > SPI_GETSCREENSAVERRUNNING only works on Win2k. The documentation is
    > > incorrect in stating that it works on Win98.

    >
    > That's not good. I installed 98 over 95 just so I could do this...
    > I looked on the online version of MSDN and noticed that it is still listed
    > for Win98 & 2000.
    >
    > <code snipped>
    >
    > I tried that code, it still returns false. Do you know of any official

    word
    > from MS that this doesn't work? I did search MSDN (again)
    >
    > Thanks,
    > Dave
    >
    >
    >




  12. #12
    Don Bradner Guest

    Re: Screensaver running? What's wrong?

    "David Crowell" <davidc@qtm.net> wrote:

    >I tried that code, it still returns false. Do you know of any official word
    >from MS that this doesn't work? I did search MSDN (again)


    I believe that all current documentation still says (incorrectly) that it is
    Win98 and 2K. This type of doc error frequently never gets fixed. For "Proof"
    you will have to go to the actual Win32 platform SDK. Find a copy of the
    winuser.h header file that is recent enough to have SPI_GETSCREENSAVERRUNNING
    and you will find that it is among the definitions sandwiched between the
    conditionals which make it 2k only:

    #if(WINVER >= 0x0500)
    #define SPI_GETSCREENSAVERRUNNING 114
    #endif /* WINVER >= 0x0500 */

    Now as to the question of whether you can detect a Win95/98 screen saver by
    some other means,, the answer is "maybe." I've long held that you can't, and I
    recently challenged Joe LeVasseur over in
    microsoft.public.vb.general.discussion when he posted code he said would work.
    Didn't work for me. When he insisted it did, I looked a bit deeper, and I
    found that, in fact, it does work, but only if the screen saver has called
    SPI_SETSCREENSAVERRUNNING.

    In testing against several standard screen savers, I found that they all
    called SPI_SETSCREENSAVERRUNNING only when password protection was on. This is
    reasonable, because the function is used to disable Ctrl-Alt-Delete, and who
    cares if there's no password protection? I was also bitten by a bug in one of
    my own screen savers that I was using to test with, because mine wasn't
    calling SPI_SETSCREENSAVERRUNNING in any case!

    So, here below is Joe's code; I hope it helps:

    Option Explicit

    Private Const SPI_SCREENSAVERRUNNING = 97
    Private Declare Function SystemParametersInfoSS _
    Lib "user32" Alias "SystemParametersInfoA" _
    (ByVal uAction As Long, ByVal uParam As Long, _
    ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

    Private Sub Form_Load()
    Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Timer()
    If SSRunning Then Beep
    End Sub

    Private Function SSRunning() As Boolean
    Dim lRetVal As Long
    Dim lRunning As Long
    On Error Resume Next
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    0&)
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    0&)
    If lRunning <> 0 Then
    SSRunning = True
    End If
    End Function

    Don Bradner
    don@arcatapet.com
    www.arcatapet.com

  13. #13
    Don Bradner Guest

    Re: Screensaver running? What's wrong?

    "David Crowell" <davidc@qtm.net> wrote:

    >I tried that code, it still returns false. Do you know of any official word
    >from MS that this doesn't work? I did search MSDN (again)


    I believe that all current documentation still says (incorrectly) that it is
    Win98 and 2K. This type of doc error frequently never gets fixed. For "Proof"
    you will have to go to the actual Win32 platform SDK. Find a copy of the
    winuser.h header file that is recent enough to have SPI_GETSCREENSAVERRUNNING
    and you will find that it is among the definitions sandwiched between the
    conditionals which make it 2k only:

    #if(WINVER >= 0x0500)
    #define SPI_GETSCREENSAVERRUNNING 114
    #endif /* WINVER >= 0x0500 */

    Now as to the question of whether you can detect a Win95/98 screen saver by
    some other means,, the answer is "maybe." I've long held that you can't, and I
    recently challenged Joe LeVasseur over in
    microsoft.public.vb.general.discussion when he posted code he said would work.
    Didn't work for me. When he insisted it did, I looked a bit deeper, and I
    found that, in fact, it does work, but only if the screen saver has called
    SPI_SETSCREENSAVERRUNNING.

    In testing against several standard screen savers, I found that they all
    called SPI_SETSCREENSAVERRUNNING only when password protection was on. This is
    reasonable, because the function is used to disable Ctrl-Alt-Delete, and who
    cares if there's no password protection? I was also bitten by a bug in one of
    my own screen savers that I was using to test with, because mine wasn't
    calling SPI_SETSCREENSAVERRUNNING in any case!

    So, here below is Joe's code; I hope it helps:

    Option Explicit

    Private Const SPI_SCREENSAVERRUNNING = 97
    Private Declare Function SystemParametersInfoSS _
    Lib "user32" Alias "SystemParametersInfoA" _
    (ByVal uAction As Long, ByVal uParam As Long, _
    ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

    Private Sub Form_Load()
    Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Timer()
    If SSRunning Then Beep
    End Sub

    Private Function SSRunning() As Boolean
    Dim lRetVal As Long
    Dim lRunning As Long
    On Error Resume Next
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    0&)
    lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    0&)
    If lRunning <> 0 Then
    SSRunning = True
    End If
    End Function

    Don Bradner
    don@arcatapet.com
    www.arcatapet.com

  14. #14
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    Thank you for clearing that up.

    Unfortunately relying on the screen saver being password protected won't
    help.

    I may have to delve into a little C for a WH_GETMESSAGE Global Hook, but I
    really don't want to <g>
    Then I'll have to also find out when the screensaver stops.

    Dave

    > I believe that all current documentation still says (incorrectly) that it

    is
    > Win98 and 2K. This type of doc error frequently never gets fixed. For

    "Proof"
    > you will have to go to the actual Win32 platform SDK. Find a copy of the
    > winuser.h header file that is recent enough to have

    SPI_GETSCREENSAVERRUNNING
    > and you will find that it is among the definitions sandwiched between the
    > conditionals which make it 2k only:
    >
    > #if(WINVER >= 0x0500)
    > #define SPI_GETSCREENSAVERRUNNING 114
    > #endif /* WINVER >= 0x0500 */
    >
    > Now as to the question of whether you can detect a Win95/98 screen saver

    by
    > some other means,, the answer is "maybe." I've long held that you can't,

    and I
    > recently challenged Joe LeVasseur over in
    > microsoft.public.vb.general.discussion when he posted code he said would

    work.
    > Didn't work for me. When he insisted it did, I looked a bit deeper, and I
    > found that, in fact, it does work, but only if the screen saver has called
    > SPI_SETSCREENSAVERRUNNING.
    >
    > In testing against several standard screen savers, I found that they all
    > called SPI_SETSCREENSAVERRUNNING only when password protection was on.

    This is
    > reasonable, because the function is used to disable Ctrl-Alt-Delete, and

    who
    > cares if there's no password protection? I was also bitten by a bug in one

    of
    > my own screen savers that I was using to test with, because mine wasn't
    > calling SPI_SETSCREENSAVERRUNNING in any case!
    >
    > So, here below is Joe's code; I hope it helps:
    >
    > Option Explicit
    >
    > Private Const SPI_SCREENSAVERRUNNING = 97
    > Private Declare Function SystemParametersInfoSS _
    > Lib "user32" Alias "SystemParametersInfoA" _
    > (ByVal uAction As Long, ByVal uParam As Long, _
    > ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
    >
    > Private Sub Form_Load()
    > Timer1.Interval = 1000
    > End Sub
    >
    > Private Sub Timer1_Timer()
    > If SSRunning Then Beep
    > End Sub
    >
    > Private Function SSRunning() As Boolean
    > Dim lRetVal As Long
    > Dim lRunning As Long
    > On Error Resume Next
    > lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    > 0&)
    > lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    > 0&)
    > If lRunning <> 0 Then
    > SSRunning = True
    > End If
    > End Function
    >
    > Don Bradner
    > don@arcatapet.com
    > www.arcatapet.com




  15. #15
    David Crowell Guest

    Re: Screensaver running? What's wrong?


    Thank you for clearing that up.

    Unfortunately relying on the screen saver being password protected won't
    help.

    I may have to delve into a little C for a WH_GETMESSAGE Global Hook, but I
    really don't want to <g>
    Then I'll have to also find out when the screensaver stops.

    Dave

    > I believe that all current documentation still says (incorrectly) that it

    is
    > Win98 and 2K. This type of doc error frequently never gets fixed. For

    "Proof"
    > you will have to go to the actual Win32 platform SDK. Find a copy of the
    > winuser.h header file that is recent enough to have

    SPI_GETSCREENSAVERRUNNING
    > and you will find that it is among the definitions sandwiched between the
    > conditionals which make it 2k only:
    >
    > #if(WINVER >= 0x0500)
    > #define SPI_GETSCREENSAVERRUNNING 114
    > #endif /* WINVER >= 0x0500 */
    >
    > Now as to the question of whether you can detect a Win95/98 screen saver

    by
    > some other means,, the answer is "maybe." I've long held that you can't,

    and I
    > recently challenged Joe LeVasseur over in
    > microsoft.public.vb.general.discussion when he posted code he said would

    work.
    > Didn't work for me. When he insisted it did, I looked a bit deeper, and I
    > found that, in fact, it does work, but only if the screen saver has called
    > SPI_SETSCREENSAVERRUNNING.
    >
    > In testing against several standard screen savers, I found that they all
    > called SPI_SETSCREENSAVERRUNNING only when password protection was on.

    This is
    > reasonable, because the function is used to disable Ctrl-Alt-Delete, and

    who
    > cares if there's no password protection? I was also bitten by a bug in one

    of
    > my own screen savers that I was using to test with, because mine wasn't
    > calling SPI_SETSCREENSAVERRUNNING in any case!
    >
    > So, here below is Joe's code; I hope it helps:
    >
    > Option Explicit
    >
    > Private Const SPI_SCREENSAVERRUNNING = 97
    > Private Declare Function SystemParametersInfoSS _
    > Lib "user32" Alias "SystemParametersInfoA" _
    > (ByVal uAction As Long, ByVal uParam As Long, _
    > ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
    >
    > Private Sub Form_Load()
    > Timer1.Interval = 1000
    > End Sub
    >
    > Private Sub Timer1_Timer()
    > If SSRunning Then Beep
    > End Sub
    >
    > Private Function SSRunning() As Boolean
    > Dim lRetVal As Long
    > Dim lRunning As Long
    > On Error Resume Next
    > lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, 0&, lRunning,
    > 0&)
    > lRetVal = SystemParametersInfoSS(SPI_SCREENSAVERRUNNING, lRunning, 0&,
    > 0&)
    > If lRunning <> 0 Then
    > SSRunning = True
    > End If
    > End Function
    >
    > Don Bradner
    > don@arcatapet.com
    > www.arcatapet.com




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center