YOUR FEEDBACK
johnpetersen wrote: Great post. You hit some good points, and hopefully me sending this post. It wil...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Creative Designs with Starter Kits
Create screen savers the newfangled way

One of the more enjoyable projects a developer can create is a Windows Screen Saver. While this type of project is not generally mainstream, it provides a break from the normal day-to-day routines. Visual Studio 2005 endeavors to provide an easier method for the creation of screen savers by providing a special project category called a Starter Kit. By selecting a Screen Saver Starter Kit, a solution is created that includes the code needed to publish a screen saver of your own. To better understand how this benefits a developer, let's quickly review an article published in the May 2003 issue of .NET Developer's Journal entitled "Informative Screen Savers" (Vol: 1, iss: 5).

Visual Studio 2003 did not include the Starter Kit type of project, so a developer who wished to create a screen saver needed to write a considerable amount of code. The developer would start with a new Windows Form Solution to begin the creation of the screen saver. From that point, objects were placed on the Windows form and code was written to handle the events and command line options that are required. An example of this would be the startup program shown in Listing 1. (See Figure 1)

The code listing is a simple example that handles the initial steps necessary to determine whether to run the screen saver or exit the application. Additionally there is the code required to handle displaying any information that a developer might want placed on the screen. The 2003 article walks through the creation of a screen saver based on the System.Management namespace. Instead of the common graphical display, local PC information was being displayed on the screen.

Beginning with Visual Studio 2005, Microsoft has introduced a new feature, called Starter Kits, to quickly design applications. Starter Kits are essentially project templates intended to provide a developer with all of the components necessary to create a useful project that runs out of the box without having to write the code from scratch. The rest of this article will focus on what the Screen Saver Starter Kit includes that is beneficial to the developer. This saves a developer time and increases productivity. To get started, open Visual Studio 2005. Select a new project and find the project type "Starter Kits." In this section will be two types of projects, the Movie Collection Starter Kit and the Screen Saver Starter Kit. Choose the Screen Saver Starter Kit and let's take a look at the code that is generated.

After accepting the default name for the project, VS2005 will generate a complete solution and open it. Initially, an HTML help page is displayed that introduces the developer to the project. This solution contains several components containing pregenerated code that is ready for compilation. Some of the key parts of the project include a Windows Form for both the screen saver and the configuration dialog, a set of classes for RSS feed processing, and several supporting files. By default the solution can be built and run out-of-the-box. The default solution is set up to run with two background images and an RSS feed. Let's take a look at the default screen saver:

  1. On the Build menu, select Build Solution
  2. Find the bin directory for your project and look for a file called ssNews.scr
  3. Copy this file to your Windows\System32 directory
  4. Right-click on your desktop, select properties, then select the Screen Saver tab
  5. Select the screen saver entitled News from the list
  6. Finally, click the Preview button to see the default screen saver
The screen saver cycles through two background images while moving through a list of five news items from the default RSS feed. The default RSS feed comes from Microsoft (http://msdn.microsoft.com/vcsharp/rss.xml), but it can be changed easily enough. Simply return to the Screen Saver tab and select the Settings button. This runs the default configuration screen in the solution. This screen allows a user to change the RSS feed. It also includes a Validate button to ensure that the RSS feed is valid. A few examples of RSS feed sites are www.lazycoder.com/weblog/wp-rss2.php and www.gps-practice-and-fun.com/rss.xml. A nice site to search for available RSS feeds is www.syndic8.com/feedlist.php, which has links to numerous feeds and information on the date the feed was validated. The default solution contains three classes for handling the RSS feed information. The classes that handle the RSS feeds deserve some attention. The classes implement a small part of the RSS 2.0 specification and do not represent the complete 2.0 specification. They can be expanded to include the full specification, and a developer could then package the classes in a DLL for reuse in other projects.

The first class in the RSS component of the solution is the RSS Channel class. This class is very simply constructed to create an RSS Channel from an XML node. The class itself contains one method and three properties. The properties represent a channel element of an XML node and include a title, a link, and an items list. The items list is created using the IList interface and is labeled with the read-only property. The next class is the RSS Feed. This class is also very simple and represents an RSS element in an RSS 2.0 XML document. It contains a property for the channels as an IList object as well as a main channel property. It contains three methods, one of which takes a string parameter, which is the URI to process. Using a WebClient, StreamReader, XMLTextReader, and an XmlDocument, the stream is read and loaded. The final class is the RSS Item. This class reads the XML document that was loaded and extracts the name of the RSS items. The class itself only contains one method, which is used to parse the items.

The majority of the processing occurs in the provided screen saver windows form. This form uses the RSS feed classes to parse the incoming feed and render the information on the screen. Using the OnPaint() and OnPaintBackground() methods, the background and RSS feed are displayed as a screen saver. Using a timer and the methods to create the information to be displayed, the form is custom rendered using GDI+. The interesting part is the My.Settings object. This object is used to retrieve the user-defined RSS feed URI and the background images to be used. To access the object in Visual Basic, use My.Settings.<propertyname>, where the propertyname is the name of the saved setting.

The My.Settings object is a part of the My Project component of the solution. This section contains all of the settings for the project. Information such as the Assembly settings, user-defined settings, an events class, etc. is included in this folder. There is also a Settings.settings section here, which is where a developer can define the settings to be saved, including the Name of the setting, type, scope (User or Application), and any default value the setting should have. When users access the Settings screen, these are the settings they will be modifying. The My Project component also contains a class, called MyApplication, which contains the methods necessary to run the application. It is here that a developer will find the Startup method. This is the method necessary to control the command line options of the screen saver. Since a screen saver is actually an executable with the extension changed from EXE to SCR, and because Windows requires a screen saver to use command line options, the developer will want to place code in this method to handle those options. By default, the solution contains code to handle the settings form and the screen saver form. The three settings that can be used on the command line are shown in Figure 2.

The last component to discuss is the Settings form. This form contains objects associated with the user-specified settings. By default it contains two sections, the RSS Feed section and the Background Images section. In the RSS Feed section the user can specify an RSS feed or use the default. Once defined, the RSS Feed site can be validated by clicking on the Validate button, which checks the URI entered by the user and returns a message box with either Valid or Invalid. This can be used to ensure that the RSS Feed is valid. The Background Images section asks the user to specify the background images to use for the screen saver, but instead of asking for a filename, the form asks for a background images folder. This provides the user with the ability to use several background images. Once the changes are applied, the settings are saved in the Settings.settings section of the Application Object. Each time the screen saver activates, it will read these settings and use them to render the screen saver to the user. Figure 3 shows the settings screen after an RSS Feed validation has occurred.

The base framework provides an excellent start for a developer to begin the creative process. There are many possibilities for a project of this nature. The most common screen savers include graphics or photos, but developers can now produce screen savers that contain news items, weather information, or a variety of other pieces of information. In the aforementioned May 2003 issue of .NET Developer's Journal, my "Informative Screen Savers" article demonstrated how to use the System.Management namespace to display practical information about the local computer. This information is most useful to a network administrator or even to helpdesk personnel; however, with a change to the original design, an entire computer room could be monitored. The possibilities are endless.

As mentioned earlier, a screen saver project is one of the more creative venues for a developer. The included documentation is very well written and worth reviewing before embarking on creating a customized screen saver. The included source code is documented, and includes classes to deal with RSS feeds. The project also includes a way to store and retrieve the configuration screen settings. So have fun and let your creativity run wild with the new Screen Saver Starter Kit.

About Larry Perry
Larry Perry has been a Microsoft developer for the past 10 years. Most of his work has centered on database development using the FoxPro/Visual FoxPro environment. Recently, however, he has been working with Visual Studio.NET and SQL Server 2000. Larry is a Microsoft Certified Application Developer for .NET and continues to learn more about Microsoft?s latest technologies, including XML and ASP.NET.

YOUR FEEDBACK
dotEd wrote: ]]] a screen saver project is one of the more creative venues for a developer [[[ I'd never thought about that but I can see you're right. Neat article.
MICROSOFT .NET LATEST STORIES
OpenSpan and TIBCO have announced a technology and business partnership designed to extend TIBCO solutions to desktop environments. The partnership will enable TIBCO Service-Oriented Architecture, Business Process Management and Business Optimization solutions to more rapidly integrate...
In a move that looks tailor-made for an antitrust suit, Microsoft says it’s going to give away a consumer security kit that it’s building code named Morro. It should be available in the second half of next year – probably more like mid-year. The freebie widgetry is supposed to de...
Tidal Software has announced Intersperse 8.0, a product that monitors J2EE and .NET applications and their transaction component performance to produce meaningful metrics for managing applications and high-level business processes. The product leverages a combination of lightweight Ja...
DataGuise has announced their first masking in place solution for multi-database environments such as Oracle, Microsoft SQL Server, and others. The dgSolution Suite provides secure masking of database content and is designed for the highest level of flexibility and functionality across...
The BlackBerryR Technical Webcast Series is designed to help BlackBerry administrators better manage and leverage the capabilities of their BlackBerry solution. Each webcast is packed with detailed technical information, covering topics that are relevant to you. Our on-demand webcasts ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Simba Technologies Inc., industry's choice for standards-based relational and multi-dimensional data...