Could anyone inform me of how I would call the screen saver on windows xp?

Edit: Just did some research on MSDN and found the WM_SYSCOMMAND, and i see something about calling the screen saver in there, but i am confused on how to use it. Any help? Thanks guys

Recommended Answers

All 11 Replies

i mean using c++ and making an app out of it lol.

Edit: I dont want to create a screen saver, but call

MSDN:
SC_SCREENSAVE
Executes the screen saver application specified in the [boot] section of the System.ini file.

Im just confused on how to use it. Thanks

#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
    return 0;
}

thx alot comatose, that works, but can u explain it to me? Also, say i wanted to allow the user to set a password to use on resume each time the app was run, any suggestions? I dont know much about win programming. Thanks!

sure, windows.h includes everything that we need. The standard C++ stuff, is just the includes, using namespaces (the namespaces and the #include <iostream> isn't even needed...it just came with the Code::Blocks IDE Blank Project, so I just left it) . So, Basically, the include directive tells the pre-compiler that we want to copy the contents of <windows.h> into our file at the top. The next step is the main function, known as the exe's entry point (the first piece of code that will run when the OS launches it) The only real line of code in the program is the SendMessage call, which is found in the windows.h file... SendMessage is a function used to basically make another window/program behave as you would want it to (ie: you can send messages to have a window minimize, maximize, close... whatever) .

SendMessage wants to know what window to send the message to. We used another function (defined in windows.h) called GetDesktopWindow, which will give us the "handle" or "hwnd" of the Desktop Window. An Hwnd is a unique hex value assigned to a window so that it can be identified by the OS. Every window has one. So, we get the hwnd for the desktop (with GetDesktopWindow) and use that hwnd, so that SendMessage knows which window we are sending a message to. The WM_SYSCOMMAND, let's the window know that we are about to send it a system command of some kind. The SC_SCREENSAVE (both WM_SYSCOMMAND and SC_SCREENSAVE are also defined in windows.h) tells the window that the particular system command, is to launch the screensaver. The zero is pretty much just a place-holder... in more complicated sendmessages it becomes needed for additional information, but 90% of the time it is zero. The return 0 (since we are returning from the main function) exits the program.

commented: Helpful +1

Thank you very much for the in depth explanation, I am already familiar with the first half, but its always good to make sure your on top of your game, thanks a lot!

The Password issue is a whole lot uglier. Since I believe it was win2k or so, the password to get into the system from the screensaver is the account password. So, if you logged into XP as ClutchKiller, then the password for the screen saver is the same one that you used to log in to XP. So, what you are essentially looking for, is how do you change the account password.... and then put it back to what it was before..

Your Welcome :)

hah, I was just scheming, and you tell me what you think about this idea, but what if i just ask for user input for a variable, and then once the screen saver is interrupted, i can do something like lock the desktop window until user inputs the correct variable code that was entered in console before SC_SCREENSAVE was called. So i guess instead of going through OS, just go through console. Sound doable? Maybe have the app detect mouse movement and thats when the console pops up again, and that would disable the screen saver as well, so that might reduce on the technicality of the source.

I'm not sure how you would go about locking the desktop window... I suppose you could try to use the "SetParent" API call, and essentially kidnap the desktop window... but I think putting it back may be a whole can of worms.

since your here, could you help me in learning to decipher how msdn explains there functions and what not. If i understood how to read it, i could make much more valuable use of msdn.

Example: http://msdn.microsoft.com/en-us/library/ms633515.aspx

HWND GetWindow(
HWND hWnd,
UINT uCmd
);

and the other stuff to is confusing. Thanks!

thats the function prototype, it shows that the function has a return type of HWND andtakes two parameters. A HWND and an UINT. msdn then explains what each of the parameters are, it also lists all the possible options for the UINT uCmd and then it states what exactly is returned.

Chris

commented: Good Description, Clear... Concise. +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.