Exploring the GrabAPicture Application (Part 1)

Sometimes it’s nice to explore a new kind of application. GrabAPicture is a Visual Basic.NET application I built for myself and have continually improved over a number of years. This application lets me record my favorite picture locations, whether they exist online, on a network, or on my location machine, and display them as wallpaper. Yes, I could have used Windows 7 functionality to create a rotating services of random pictures, but I wanted to create my own application. It does have some advantages over the Windows 7 option:


  • The command line interface makes it possible to add the application to the Startup folder, access the application from a shortcut, or execute the application from a command prompt.
  • The application has the ability to use both network and online resources.
  • I can individually adjust how I want each picture displayed. If one picture looks better tiled and another stretched, I have that option.

Of course, it’s always nice to play around and see what you can do. This example builds on techniques found in .NET Framework Solutions: In Search of the Lost Win32 API and Professional Windows 7 Development Guide. Some of the techniques, such as saving the settings to an XML file in the user’s C:\Users\UserName\AppData\Roaming\GrabAPicture folder are ported from C# applications I created in the past. I’m also trying out a few entirely new techniques in this application. In short, it’s a combination of techniques both old and new.

To achieve my goal, I’m using some exotic techniques, such as PInvoke to change the wallpaper. I’m also creating a serializable class to hold the application data and make it easy to work with. The example uses several forms that are specially configured to ensure GrabAPicture works as expected. As previously mentioned, it includes a fully functional command line interface that lets you adjust everything from the command line if desired. Of course, you can also work with the GUI.

You’ll find a new installment for this series every Friday. I have no idea right now of just how many installments the application will require—that depends on how many reader queries I receive and just how far I have to break the application down in order to make it easy to understand. When I’ve completed this series, you’ll be able to create your own version of GrabAPicture and hopefully improve on it. In fact, I’ll provide some ideas as we go along of things I’d like to add.

Let’s get started with a quick overview of the user interface. When you start GrabAPicture, you’ll see the current application settings as shown here.


If desired, you can type the location of a wallpaper file into the Wallpaper Location field, click Set Value, and have it change the wallpaper on your desktop. However, the more common way to use this application is with a random source, which you access by clicking Random Sources. This dialog box contains local and remote sources as shown here.


I chose to separate local sources (including those on the local network) from remote sources (those on the Internet) so that the application could continue to do its job using just local or just remote sources if desired. Each source has four buttons associated with it. You can add new sources, edit existing sources, delete a source you no longer want, and select a particular source for use immediately.

Selecting or deleting a source doesn’t require much additional work. However, the other two activities require that you obtain additional information from the user. Adding or editing a source displays a customized version of the following dialog box (the customization occurs in code—the application doesn’t actually use multiple forms).


You give each source a name and a location. The entry also includes a style selection that tells Windows how to display it. The example is currently compatible with older versions of Windows, so it includes the Stretched, Centered, and Tiled settings. In a later blog post, I’ll show how to update these settings to something that’s Vista or Windows 7 specific so it will include the Fill and Fit options.

Most command line utilities rely on a text-based help screen. I chose to include a GUI help screen for GrabAPicturejust to be different and to demonstrate how you’d perform this task (since there aren’t any other examples that I can find). When you type GrabAPicture /? and press Enter at the command line, you see the following help screen.


Well, that’s about it from a design perspective. Let me know if you have any questions at [email protected]. You can see the next post in this series at Exploring the GrabAPicture Application (Part 2).