News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to turn off screensaver?

Started by uziq, March 31, 2007, 11:00:07 PM

Previous topic - Next topic

uziq

I can turn on the screensaver with:
invoke SendMessage, eax, WM_SYSCOMMAND, SC_SCREENSAVE, TRUE
but I can't seem to turn it off.

Also, why doesn't this turn on the screensaver?
invoke SystemParametersInfo, SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0

Is it safe to use HWND_BROADCAST, or must I use GetDesktopWindow (proper way of doing it)?


.486
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
start:
    invoke GetDesktopWindow
    invoke SendMessage, eax, WM_SYSCOMMAND, SC_SCREENSAVE, TRUE
    ;invoke SystemParametersInfo, SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0

    ;invoke Sleep, 3000
    ;invoke GetDesktopWindow
    ;invoke SendMessage, HWND_BROADCAST, WM_SYSCOMMAND, SC_SCREENSAVE, FALSE

    invoke ExitProcess, NULL

end start

PBrennick

uziq,
Have you tried sending a message to the screensaver using DefScreenSaverProc with WM_ACTIVATE, FALSE ?

By the way, SC_SCREENSAVE, FALSE does not exist as a possibility, only TRUE is supported.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

uziq

hmm.. I gave it a try and got:
QuoteScreenSaver.exe - Unable To Locate Component
This application has failed to start because scrnsave.dll was not found. Re-installing the application may fix this problem.

.486
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\scrnsave.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\scrnsave.lib

.code
start:
    invoke GetDesktopWindow
    invoke SendMessage, eax, WM_SYSCOMMAND, SC_SCREENSAVE, TRUE
    ;invoke SystemParametersInfo, SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0

    invoke Sleep, 3000
    ;invoke GetDesktopWindow
    ;invoke SendMessage, HWND_BROADCAST, WM_SYSCOMMAND, SC_SCREENSAVE, FALSE
    invoke DefScreenSaverProc, HWND_BROADCAST, WM_ACTIVATE, FALSE, FALSE

    invoke ExitProcess, NULL

end start


WinXPSP2

PBrennick

uziq,

What you need to do is get the handle to the screensaver so that when you send the message, it will get added to the queue. The code to do this will be something like the following:



.data
;------------------------------------------------------
app         db  'screensaver.exe', 0
wndclass    db  'Don't know what you should put here', 0
childclass  db  'Don't know what you should put here', 0

.code
;------------------------------------------------------
;   some code ....
    invoke  FindWindow, ADDR wndclass, 0
    invoke  FindWindowEx, eax, 0, ADDR childclass, 0
    mov     handle, eax
;   The rest of the story...


For wndclass and childclass I usually use the name of the app, such as 'GeneSys' for the first one and 'Edit' for the second one.
Erol wrote an autotyping example that sends text to Notepad, while this is not what you want to do, the process of finding a way to get to the message pump is the same, so it should help you as keypresses go drop through the pump.

Hope this helps,
Paul
The GeneSys Project is available from:
The Repository or My crappy website

uziq

Thanks for the help, but I didn't get anywhere with it..

I did finally manage something though. :)
This works:
.486
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
start:
    invoke GetDesktopWindow
    invoke SendMessage, eax, WM_SYSCOMMAND, SC_SCREENSAVE, TRUE

    invoke Sleep, 3000

    invoke GetForegroundWindow
    invoke PostMessage, eax, WM_CLOSE, 0, 0

    invoke ExitProcess, NULL
end start


However, these two links mention that OpenDesktop, EnumDesktopWindows, and CloseDesktop may need to be used instead:
http://support.microsoft.com/kb/140723
http://www.codeproject.com/csharp/ScreenSaverControl.asp

I'm not sure how to do that in MASM. :(

Any assistance would be appreciated, as I'd like to get this working with Win2K.

edit: actually it seems to work fine in Win2K, without the extra code (which I guess is only needed in special circumstances?)..
edit2: hmm.. it has the nasty side-effect of closing the foreground window (GetForegroundWindow), when the screensaver is NOT already running.

uziq

ah, here we go. Just need to check if it's running or not. :bg

.486
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
isRunning dd 0

.code
start:
    invoke SystemParametersInfo, SPI_GETSCREENSAVERRUNNING, 0, isRunning, 0
    .if isRunning
        invoke GetForegroundWindow
        invoke PostMessage, eax, WM_CLOSE, 0, 0
    .endif
    invoke ExitProcess, NULL
end start


There's still the Win2K issue that MS mentions..  :(