How can I write a screen saver for Windows in C++?

kalani picture kalani · Mar 2, 2011 · Viewed 8.9k times · Source

I want to write a screen saver for Windows using the Windows API. How can I start to write it?

Answer

Holstebroe picture Holstebroe · Mar 2, 2011

Basically a screensaver is just a normal application that accepts a few command line options, provided by windows, to determine if it should start fullscreen or in a preview window.

So, write a normal exe-application that takes the following command line arguments (from http://msdn.microsoft.com/en-us/library/ms686421(v=vs.85).aspx):

  • /s – Start the screensaver in full-screen mode.
  • /c – Show the configuration settings dialog box.
  • /p #### – Display a preview of the screensaver using the specified window handle.

Next check out some DirectX / OpenGL / SDL tutorials and write some eye candy.

Obviously you should check for mouse movements and key presses and exit your application if the user wakes up.