Blog of David Bautista, containing my thoughts, comments and questions. RSS Feed


A WPF Screen Saver Library

While Visual Studio 2005 includes a starter project for writing managed screen savers, it [the screen saver] doesn’t support display in the Screen Saver Settings dialog’s preview window, and isn’t built around WPF.  As an exercise for learning WPF and WPF 3D—but also because I have a thing for screensavers—I put together a WPF-based library for this.

The WPF screen saver library contains much of its functionality in a System.Windows.Window child class.  This provides a message loop to drive execution.  In full-screen mode, it closes when the user presses a key or makes a significant mouse movement, and in preview mode, when its parent window is no longer displayed.

The API is fairly simple:

// Create a window, specifying a System.Windows.Media.Visual, parent window

// handle, and priority.  For full-screen, the parent handle should be IntPtr.

// Zero.  An UpdateScreenSaverStateHandler delegate can also be supplied, in

// case the visual's state needs updating--otherwise, it should be null.  In

// preview mode, the window will check that its parent is still displayed by a

// frequency, based on the specified priority.

 

ScreenSaverWindow window =

    new ScreenSaverWindow(

        someVisual,

        new UpdateScreenSaverStateHandler(someVisual.UpdateVisual),

        somePriority,

        parentHandle);

 

// Use that as the application's main window.

 

Application application = new Application();

application.Run(window);

 

Known Issues:

·         ScreenSaverWindow can't actually display on the desktop root.  Rather, it maximizes, using WindowStyle.None.  Whether this will span multi-screen displays depends on how the OS is set to handle maximizing.

·         The screen saver originally stored its settings in user/assembly Isolated Storage.  However, when run due to inactivity under Vista—it worked fine under Server 2003 and in preview mode—it couldn’t read the settings file.  Currently, the program saves to the user’s home path, but the Isolated Storage problem needs to be addressed.

·         Like some—many?—WPF apps, the example implementation takes a bit longer to load than one might like.  NGen helps, but doesn’t recognize the .scr file as an executable.

 

Source and binaries are available here.

 

The example implementation is a port of xscreensaver’s Lava Lite.  The original source is available at http://www.jwz.org/xscreensaver/.  Xscreensaver is Copyright (c) 2002-2004 Jamie Zawinski jwz@jwz.org.

 

The code for displaying in a preview window is based on Microsoft’s Create a Screensaver with GDI+ Code Sample.

Edit: Fixed the Download Link
 
Posted by Dave Bautista | 2 Comments | Trackback Url | Bookmark with:        
Tags:

Links to this Post

Comments

Monday, 14 Jan 2008 06:24 by ¿it's the original source?
sorry for my english i have a cuestion for you how many modifications did in the original source to make this? it's easy? i'm thinking on make a windows port of xscreensaver’s BSOD it's possible? Reggards Daniel Bugueño - Chile

Wednesday, 30 Jan 2008 06:08 by Re: ¿it's the original source?
Given the the original source is [for the most part] in C, there was quite a bit to do, translating it all to C#. It might have been easier, getting it to compile as a Managed C++ library, and just doing the presentation layer in C#. Also, XScreenSaver uses OpenGL, which has a stream-like API, so I had to re-work large sections for WPF 3D's mesh-based one. However, as the BSOD screen saver's all 2D, that shouldn't be as much an issue. DB

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation