Results 1 to 5 of 5

Thread: How to avoid screensaver / keep win alive ?

  1. #1

    How to avoid screensaver / keep win alive ?

    Hey,

    I am trying to avoid that screensaver kicks in on a win XP machine (changing the system settings is unfortunately not an option)
    I have tried the Win function SetThreadExecutionState. But this function seems not to work in TB (well, in some MSDN documentation it stated that it may not work from a user call at all).

    Does anybody have a different idea of:
    - how to avoid that the screensaver starts
    - how to avoid that win goes into sleep/hibernate mode
    with TB.

    (TB has a nice PC module - but not the functions i am looking for)

    Any idea is really appreciated.....

    best regards

    Christian

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: How to avoid screensaver / keep win alive ?

    Hi,

    I am not sure about monitor powerdown, but screensaver can be prevented easily:
    - handle WM_SYSCOMMAND event
    - filter out SC_SCREENSAVER
    - call SystemParametersInfo API

    I have working example for you here:
    [code=thinbasic]
    USES "UI", "Console"

    ' -- ID numbers of controls
    Begin Const
    %btnClose = 1000
    End Const

    ' -- Declare API
    %SPI_SETSCREENSAVEACTIVE = 17
    %SPIF_SENDWININICHANGE = &H2
    DECLARE FUNCTION SystemParametersInfo LIB "USER32.DLL" ALIAS "SystemParametersInfoA" (BYVAL uAction AS DWORD, BYVAL uParam AS DWORD, BYVAL lpvParam AS LONG, BYVAL fuWinIni AS DWORD) AS LONG

    ' -- Create dialog here
    FUNCTION TBMAIN()
    LOCAL hDlg AS DWORD

    DIALOG New 0, "<Enter title here>",-1,-1, 160, 120, _
    %WS_POPUP Or %WS_VISIBLE Or _
    %WS_CLIPCHILDREN Or %WS_CAPTION OR _
    %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg

    ' -- Place controls here
    CONTROL ADD BUTTON, hDlg, %btnClose, "Click to close", 95, 100, 60, 14, CALL btnCloseProc

    DIALOG SHOW MODAL hDlg, CALL dlgProc

    END FUNCTION

    ' -- Callback for dialog
    CALLBACK FUNCTION dlgProc()

    ' -- Test for messages
    SELECT CASE CBMSG

    CASE %WM_INITDIALOG
    ' -- Put code to be executed after dialog creation here

    CASE %WM_COMMAND
    ' -- You can handle controls here

    'SELECT CASE CBCTL
    '
    ' CASE ...
    ' IF CBCTLMSG = ... THEN
    '
    ' END IF
    '
    'END SELECT

    CASE %WM_SYSCOMMAND
    select case cbwparam
    case %SC_SCREENSAVE
    printl "Screensaver wanted to launch..."
    SystemParametersInfo (%SPI_SETSCREENSAVEACTIVE, %TRUE, 0, %SPIF_SENDWININICHANGE)
    function = 0

    case %SC_MONITORPOWER
    printl "Monitorpower - not sure what to do"
    function = 0

    end select

    CASE %WM_CLOSE
    ' -- Put code to be executed before dialog end here

    END SELECT

    END FUNCTION

    ' -- Callback for close button
    CALLBACK FUNCTION btnCloseProc()

    IF CBMSG = %WM_COMMAND THEN
    IF CBCTLMSG = %BN_CLICKED THEN
    ' -- Closes the dialog
    DIALOG END CBHNDL
    END IF
    END IF

    END FUNCTION
    [/code]


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to avoid screensaver / keep win alive ?

    Using Petr suggested code I've created a new version of the script.
    When executed, the script will immediately de-activate current screen saver for the current working session
    Script will than remain active and count elapsed seconds since the next screen saver activation (that should not occur)

    I've tested script under WINXP SP3.

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: How to avoid screensaver / keep win alive ?

    Petr, Eros,

    I am really impressed about the level of help you are providing - for sure this is a great community !

    As soon as I have ramped up with my knowledge and capabilities I hope to contribute in this community too.

    best regards

    Christian

  5. #5

    Re: How to avoid screensaver / keep win alive ?

    Hi Chris,

    welcome here and don't be afraid to ask.

    Michael

Similar Threads

  1. Artificial Screensaver Demo :-D
    By Lionheart008 in forum TBGL ScreenSavers
    Replies: 8
    Last Post: 04-02-2009, 13:48

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •