PDA

View Full Version : How to avoid screensaver / keep win alive ?



chris_bdnsee
14-03-2009, 22:00
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..... :D

best regards

Christian

Petr Schreiber
14-03-2009, 22:29
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:


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



Petr

ErosOlmi
15-03-2009, 12:17
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

chris_bdnsee
15-03-2009, 20:08
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

Michael Hartlef
15-03-2009, 22:25
Hi Chris,

welcome here and don't be afraid to ask.

Michael