Customising Your Desktop with Visual Basic.NET 2005

Introduction

If you followed my previous article about changing the wallpaper on your computer (Wallpaper Changer), you would know by now that I’m quite lazy and like to make things easier for myself. With Wallpaper Genie (In the above link), I changed the wallpaper only; curiosity got the better of me, and I decided to take it one step further. With this article, I will demonstrate how launch, configure, and preview screen savers on your own form; I will also demonstrate how to change the computer’s Visual style (along with the fonts, and colours pertaining to the particular visual style), determine whether your application is themed or not, as well as disabling a certain theme. Lastly, I will demonstrate how to determine the current screen resolution and change it. Sound exciting? Well then, it’s time to get started.

Concepts

Okay, you won’t start just yet. Let me first explain the intricacies surrounding what makes your desktop tick, and start off by explaining how the system wallpaper works and what you need to do to set it from your program.

Wallpaper

The current system wallpaper location is usually stored in the HKEY_CURRENT_USER\Control Panel\Desktop Registry key in the setting of Wallpaper. The wallpaper style (Tiled, Stretched, Center) is also stored in the same Registry key; these values are controlled by the TileWallpaper and WallpaperStyle settings, but I won’t go into great detail here because all of this is explained in the Wallpaper Changer article. What you need to do to change the current wallpaper from your own application, would be to write the appropriate values to these keys in the Registry as well as to use the SystemParametersInfo API to set the new wallpaper and update the current system settings. Later on in this article, I will properly demonstrate how to do this.

Resolution

Getting the current resolution settings is actually surprisingly easy; all you need to do is to use the System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width property to get the resolution width, and the same applies to the height. Changing the resolution settings is not this simple, unfortunately, but it’s luckily not too complicated either! What you will need to do is to use the EnumDisplaySettings and the ChangeDisplaySettings APIs; because of these API functions’ parameters, you will also need various Constants, and of course the DevMode1 structure that takes care of the height and width settings.

Screen Saver

The current System screensaver is also stored in HKEY_CURRENT_USER\Control Panel\Desktop Registry key, in the setting SCRNSAVE.EXE, but only if a screensaver has been set. To run the current screensaver, all you need to use is the SendMessage API. Running a different screensaver is also quite simple; you achieve this just by using the Start method of a Process object. Now, to configure you need to start the screensaver process with the configure parameter; to preview a screensaver within your program, you need to call the preview parameter along with a handle to a picturebox object. (In other words, that is telling the screensaver where to show its preview.)

Theme & Visual Style

All Theme and Visual Styles settings are stored within the HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\ThemeManager Registry key. The name & location are stored under DllName. The selected style colour available for the particular Visual Style is also stored in the same place, but under the name of ColorName. Some Styles & Themes may have more than one colour available. Another easy way to determine the various colours available is by opening the “C:\WINDOWS\Resources\Themes” folder. By doing that, you will see the names of all the various Styles on the System; open one of those folders (for example, Luna), within that folder, and you will see another folder named Shell. If you were to open the Shell folder, you will see more folders (yes, there are a lot of folders, so bear with me); for example NormalColor, HomeStead, and Metallic—within these folders there is usually a DLL file applying this colour. The Font used with the Theme is stored in the SizeName setting, also in the same key. The value for the SizeName setting can be any one of NormalSize, LargeFont, and ExtraLargeFont.

Starting Your Design

If you haven’t fallen asleep during my explanations concerning what is needed and how things work, you are ready to continue designing your interface.

Design

Add the following controls with their settings to your form:

Control Property Setting Description
GroupBox Name grpWall Holds all the Wallpaper Settings Controls
  Text Wallpaper Settings
Button (Inside grpWall) Name btnWall Enables you to change the Wallpaper
  Text Change Wallpaper
GroupBox Name grpTheme Holds all the Theme Settings Controls
  Text Theme Settings
Button (Inside grpTheme) Name btnAppThemed Determines whether or not your Application is Themed
  Text Is Application Themed?
Button (Inside grpTheme) Name btnThemeActive Determines wWhether or not a theme is active
  Text Is Theme Active
Button (Inside grpTheme) Name btnDisTheme Disable the current Theme (System wide)
  Text Disable Theme
GroupBox Name grpScreenRes Holds all the Screen Resolution Settings controls
  Text Screen resolution Settings
Button (Inside grpScreenRes) Name btnGetRes Get current Screen Resolution
  Text Get Screen Resolution
Button (Inside grpScreenRes) Name btnChangeRes Change Screen Resolution
  Text Change Screen Resolution
ListBox (Inside grpScreenres) Name lstResolution Shows Available Screen Resolution settings
  Items 640 x 480
800 x 600
832 x 624
1024 x 768
1152 x 864
1280 x 600
1280 x 720
1280 x 768
1280 x 960
1280 x 1024
GroupBox Name grpVisStyles Holds all Visual Settings controls
  Text Visual Style Settings
Label (Inside grpVisStyles) Name Label1 Indicates Action to Take with cboStyles
  Text Select Visual Style
Label (Inside grpVisStyles) Name Label2 Indicates Action to Take with cboStyleColor
  Text Select Style Color
Label (Inside grpVisStyles) Name Label3 Indicates Action to Take with cboStyleFonts
  Text Select Style Font
ComboBox (Next to Label1, Inside grpVisStyles) Name cboStyles Display all the System Visual Styles
ComboBox (Next to Label2, Inside grpVisStyles) Name cboStyleColor Display all the available Style Colours
ComboBox (Next to Label3, Inside grpVisStyles) Name cboStyleFonts Display all the available Style Fonts
  Items Normal
Large Fonts
Extra Large Fonts
Button (Inside grpVisStyles) Name btnSetStyle Sets the new Visual Style for the system, with all specified Settings
  Text Apply Visual Style
GroupBox Name grpScreenSaver Holds all ScreenSaver Settings controls
  Text ScreenSaver Settings
ListView (Inside grpScreenSaver) Name lvScreen Lists the System’s Screensavers, and shows descriptions of each
  View Details
lvScreen Column Name ScreenName Shows Screensaver name in lvScreen
  Text Screensaver
  Name ScreenDesc Shows Screensaver Description in lvScreen
  Text Description
GroupBox (Inside grpScreenSaver) Name grpSelScreen Enables you to work with selected (in ListView) screensaver
  Text Selected Screen Saver Settings
Button (Inside grpSelScreen) Name btnDiffScreen Start Selected Screensaver
  Text Start Selected Screen Saver
Button (Inside grpSelScreen) Name btnPreviewScreen Preview Selected Screensaver
  Text Preview Selected Screen Saver
Button (Inside grpSelScreen) Name btnConfScreen Configure Selected Screensaver
  Text Configure Selected Screen Saver
Button (Inside grpScreenSaver) Name btnDefScreen Starts Current System Screensaver
  Text Start Default Screen Saver
Button (Inside grpScreenSaver) Name btnStopScreen Stops all Screensaver Processes
  Text Stop Screen Saver Activities
PictureBox (Inside grpScreenSaver) Name picPreviewScreen Shows the Preview of selected Screensaver
  BorderStyle FixedSingle

Your design should now look like the following picture:

More by Author

Must Read