Daily Archive for December 21st, 2006

Photo Screen Saver

Using my new template, I wanted to create a screen saver for my photos.  I liked the look of the Picasa screen saver and wanted to see if I accomplish something similar in WPF.  Below is the result. 

The photos animate in & out to random locations.  It’s also configurable to show photos from any directory on your machine.

You can get the screen saver here.  

To Install

  1. Be sure you have .NET Framework 3.0.   (If you’re running Vista, you’re good to go!)
  2. Download the ZIP file and Extract All files.
  3. Copy the PixPile.scr file to convenient location on your C: drive.
  4. Right click the PixPile.scr file.
  5. Select Install.

To Configure

  1. In the Windows Screen Saver Dialog, select the PixPile screen saver.
  2. Click Settings button.

To Uninstall:

  1. Delete the Spiral.scr file.

 

08 Jan 07: 

  • Fixed a crash after long runs.

18 Jan 07: 

  • Changed photo “drop shadow” from using a BitmapEffect to an transparent Rectangle to enhance perf.  
  • Reduced border size and tweeked fade in animation, 
  • Added setting to change min and max photo size to work better with screens of different resolutions.

WPF Screen Saver Visual Studio Template!

I thought it would be fun to create a WPF screen saver.  I built one with Robert Hogue’s most excellent Material Group “Background Animation” visuals.  (You can find it in his Sample Pack.)  You can download the screen saver and/or the code.

However, I thought it would be even more fun if everyone else would write screen savers too.  :) To facilitate this, I’ve written a VS template for WPF screen savers.

Screen Saver Template – Installation Instructions

  1. Download the template here.
  2. Move the zip file to <MY DOCUMENTS>Visual Studio 2005TemplatesProjectTemplatesVisual C#”..  (DO NOT unzip it)

When creating a new project, “Screen Saver Application (WPF)” will now be an ”Visual C#” project type option.

 

Deploying the Screen Saver

In order to deploy your screen saver, you must rename the RELEASE build of the screen saver executable to have a “.scr” extension:

  1. Go to binRelease folder of your project.
  2. Rename the .exe to .scr.  (e.g.”ScreenSaver.exe” becomes “ScreenSaver.scr”)
  3. If using .NET Application Settings, see important note below.

Installing the Screen Saver

To install on a user’s machine:

  1. Copy the .scr file (& any dependent files) to convenient location on your C: drive.
  2. Right click the .scr file.
  3. Select Install.

To configure on a client machine:

  1. In the Windows Screen Saver Dialog, select the screen saver.
  2. Click Settings button.

To uninstall:

  1. Delete .scr file.

Screen Saver Files

The template creates the following main files for you:

  1. App.xaml/App.xaml.cs – sets up screen saver application.
  2. Window1.xaml/Window1.xaml.cs – main visuals of screen saver
  3. Settings.xaml/Settings.xaml.cs – settings window of screen saver

Screen Saver Modes

The screen saver can be launched with different command line arguments:

  • <no args>: Display screen saver
  • “/s”:  Display screen saver
  • “/c”:  Show settings window

Debugging

In DEBUG configurations, the screen saver window’s “topmost”-ness and “shutdown on key/mouse input” are disabled. To close the window, hit Ctl-F4.

To debug the settings window…

  1. Go to the project properties pane. (Right click the project in the Solution Explorer
    & select “Properties”).
  2. Select Debug on the left tabs.
  3. Find “Command Line Args” textbox under “Start Options”.
  4. Enter: /c

Saving Screen Saver Settings

I highly recommend using the .NET Application Settings feature to save user-configured screen saver settings.

Here’s the quick run down of how to do it.

  1. Determine which settings you need.  The default settings store only supports limited Type, so make sure to use an appropriate format.
  2. Add the settings to the Settings.settings file using the designer.  By default, these are saved to a per user, file system-based .NET settings store.
  3. Access the settings using Properties.Settings.Default.YourSettingName.

For the screen saver above, I defined one setting in the designer:

In my Settings.xaml.cs file, I accessed it:

 //initialize color picker with BackgroundColor application setting
TypeConverter colorTypeConverter = TypeDescriptor.GetConverter(typeof(Color));
MyColorPicker.Color = (Color) colorTypeConverter.ConvertFrom(Properties.Settings.Default.BackgroundColor) ;

As well as saved it:

//set BackgroundColor application setting to color picker's color
TypeConverter colorTypeConverter = TypeDescriptor.GetConverter(typeof(Color));
Properties.Settings.Default.BackgroundColor = colorTypeConverter.ConvertTo(MyColorPicker.Color, typeof(string)) as string;
            
//flush application settings
Properties.Settings.Default.Save();

Finally, I renamed “MaterialGroupScreenSaver.exe” to “Spiral.scr.”

IMPORTANT NOTE:

By default, the .NET Application Settings framework stores user settings based on the executing assembly name.   If you use .NET Application Settings with the default settings store,
YOU MUST GIVE YOUR SCREEN SAVER ASSEMBLY A NAME WITH 8 CHARACTERS OR LESS.

Why? The Windows Screen Saver Dialog launches the screen saver (for settings & preview) using the full assembly name (e.g. MyCoolScreenSaver.scr).  However, when launching the screensaver for real, Windows uses the shortened version (e.g. MYCOOL~1.SCR). Since the name is different, the settings are loaded from a different place.

 

Release Notes

  • Does not support real time preview in the Windows Screen Saver Dialog’s embedded display.
  • The screen saver duplicates the visuals on each monitor by creating an additional instances of Window1.