Announcement

Collapse
No announcement yet.

What's wrong with my code???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What's wrong with my code???

    I am TRYING to write a very simple program that toggles the
    screen saver enabled/disabled state. I am using it on a
    Windows 98 SE platform. The code follows:

    #COMPILE EXE
    #INCLUDE "win32api.inc"
    #RESOURCE "test!.pbr" 'simply adds an icon
    '
    FUNCTION PBMAIN() AS LONG
    CALL SystemParametersInfo(SPI_GETSCREENACTIVE,%NULL,A&,0)
    SELECT CASE A&
    CASE %TRUE
    B$ = "Screen saver *IS* active." + CHR$(13) + CHR$(13)
    C$ = "Would you like to toggle it to 'INACTIVE'?"
    D$ = B$ + C$
    Ans& = MSGBOX(D$,%MB_ICONQUESTION OR %MB_YESNO,"Continue?")
    IF Ans& = %IDYES THEN CALL SystemParametersInfo(%SPI_SETSCREENSAVEACTIVE,_
    %FALSE,%NULL,0)
    CASE %FALSE
    B$ = "Screen saver is *NOT* active." + CHR$(13) + CHR$(13)
    C$ = "Would you like to set it to 'ACTIVE'?"
    D$ = B$ + C$
    Ans& = MSGBOX(D$,%MB_ICONQUESTION OR %MB_YESNO,"Continue?")
    IF Ans& = %IDYES THEN CALL SystemParametersInfo(%SPI_SETSCREENSAVEACTIVE,_
    %TRUE,%NULL,0)
    END SELECT
    END FUNCTION

    The problem with this program is that it ALWAYS says that the
    screensaver is NOT active, even though I quadruple checked to
    ensure that it were!

    Anybody got any ideas?

  • #2
    Clay,

    One of the things being wrong is the "SPI_GETSCREENACTIVE" param that should be read as
    "%SPI_GETSCREENsaveACTIVE".
    But apart from that, the call returns 0 which means something is wrong.
    Most probably with the "A&" param which seems to be a special case.
    Someone experienced in this field?

    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    [This message has been edited by Egbert Zijlema (edited August 22, 2000).]

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

    Comment


    • #3
      It should point to A&, like VARPTR(A&). The following returns 1
      in A& if the Screen Saver is enabled:

      CALL SystemParametersInfo(%SPI_GETSCREENSAVEACTIVE, %NULL, VARPTR(A&), 0)


      ------------------

      Comment


      • #4
        Thank you, thank you! Changing it from simply "A&" to
        VARPTR(A&) got it to work! <big toothy grin>

        Thanks, Borje!


        ------------------

        Comment

        Working...
        X