|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS Visual Studio 2005
Creative Designs with Starter Kits
Create screen savers the newfangled way
By: Larry Perry
Oct. 28, 2005 10:00 PM
Digg This!
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).
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:
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.
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
|||||||||||||||||||||||||||||||||||