Advertisment

Jazz up your apps on Windows 7

author-image
CIOL Bureau
Updated On
New Update
BANGALORE, INDIA: Last month we looked at application compatibility for your apps on Windows 7 and how to get them to actually work correctly on the new OS. This month we dive into a couple of new features of Windows 7 and show how you can add them easily to 'light up' your applications on Windows 7. This will give your end-users, who are on Windows 7, a nice new feedback system, and also provide good performance on older versions.
Advertisment

All new features in Windows 7 are available using the Windows 7 SDK. However for this series, we'll perform these tasks with .NET. You will need Visual Studio 2008 or Visual C# Express 2008 with service pack 1. You will also need the Windows API Code Pack for .NET from http://tinyurl.com/ohbsuq.

Download the file and extract it anywhere on your system. Now create a new Windows application project and then add two existing projects from within the WindowsAPICodePack folder where you extracted the archive ? Core and Shell. Also add these two projects as 'references' to the Windows application project you created. This will enable your WinForms project to use the new features in Win7.

Windows 7 has a very new and revamped Taskbar that has a ton of new features. We'll explore each of these features and how you can enhance your applications with them in the coming months as well. For this issue, we'll take a look at some cool features Icon Overlays, Application ID and Progress Status.
Advertisment

Icon Overlays

In earlier versions of Windows, whenever an application wanted to display some status to the user, it would use the Notification Area/System Tray (the place near the clock on the Taskbar) to show up an icon. This was 1) fairly counter-intuitive as most people would miss it and 2) will not work nicely on Windows 7 as the Notification Area is by default kept clean and all icons are pushed off into a popup bubble ? where it will not be seen most probably.

In Windows 7 there is a much better way of doing this. You can now display a status icon over the application's icon on the Taskbar ? which makes it much easier to notice. A lot of new apps are now doing precisely this to draw attention to a status. For instance Windows Live Mail and the new Outlook 2010 display a new mail icon over the application icon whenever there are any unread e-mails. You too can add this into code in your application. First open the code for your main form and add the following using statements at the top:

Add the Core & Shell projects as reference from the Windows API Code Pack for your project.
Advertisment

using Microsoft.Windows APICodePack. Shell;

using Microsoft.Windows APICodePack. Shell.Taskbar;

Now drop a button on the form and add the following into the button's click event:

private void btnOverlay_Click(object sender, EventArgs e)

{ if (Taskbar.OverlayImage.Icon == null) Taskbar.OverlayImage = new OverlayImage(SystemIcons.Asterisk, "Hello");

else

Taskbar.OverlayImage = null;}

Advertisment

This simple code first checks whether the application's icon already has an overlay set and if not, adds a simple icon from the system icons. Note you can load any icon from a resource file for your app if you want. Such a code would allow you to display different icons to represent the status of your application at different times, which the user can view to get immediate feedback even if he is working on something else.

Application ID

Another nice feature of Windows 7 is the Taskbar grouping of an application's icons. If there are multiple instances of an application, they are all automatically grouped under the same icon on the Taskbar to save space. You can however control this by using a feature known as Application ID.

 

Advertisment

Every application has an AppID which is automatically generated for it from the name of the executable and path + some metadata. You might choose that your application shows as different icons based on different criteria ? say parameters from a shortcut or application launch buttons. To do this all you need to do is change the AppID for the running app. You can also do the reverse: have two different apps to combine under a single icon by using the same AppID in both ? say in an application suite launcher.

To do this in our sample app, drop in a button and in the click event add the following:

Advertisment

private void btnAppID_Click(object sender, EventArgs e)

{ System.Diagnostics.Process.Start(Application.ExecutablePath, "Random");

}

This basically starts up the same app with a command line argument of 'Random.' You should also add the following in the form's constructor:

public Form1()

{InitializeComponent(); String<> AppID =

System.Environment.GetCommandLineArgs();

if (AppID.Count() > 1)

Taskbar.AppId = AppID<1>;

}

Advertisment

This code checks whether the application had a startup argument and if it did, the application ID is changed to this new value. When you run the application normally, it will group the windows under the same icon. However, if you use the button you created above to launch a new window you will see a new icon appear on the Taskbar. You can use combinations of these to get the effect you want quite nicely.

Progress status icons

The next feature we'll take a look at is the ability for icons on the taskbar to display progress bars. For instance, when you copy a file to a different folder or download a file using IE, you will be able to see the progress bar in the icon itself.

To add this in your application, first drop a ComboBox, Button and ProgressBar control on the form. Add the values: ?Normal?, ?Error?, ?Paused?, ?Indeterminate? and ?NoProgress? to the ComboBox. Now add the following in the button's click event:

private void btnProgress_Click(object sender, EventArgs e)

{

if (progressBar1.Value > progressBar1.Maximum)

progressBar1.Value =

progressBar1.Minimum;

progressBar1.Increment(10);

switch

(comboBox1.SelectedItem.ToString()) {

case "Normal": Taskbar.ProgressBar.State =

TaskbarButtonProgressState.Normal; break;

case "Error": Taskbar.ProgressBar.State =

TaskbarButtonProgressState.Error; break; case "Paused": Taskbar.ProgressBar.State =

TaskbarButtonProgressState.Paused; break; case "Indeterminate": Taskbar.ProgressBar.State =

TaskbarButtonProgressState.Indeterminate; break; case "NoProgress": Taskbar.ProgressBar.State =

TaskbarButtonProgressState.NoProgress; break; default: Taskbar.ProgressBar.State = TaskbarButtonProgressState.Normal;

break;

}

Taskbar.ProgressBar.CurrentValue = progressBar1.Value;

}

 



This code increases the value of the progress bar in the window and at the same time also increases the value of the progress bar in the application icon. The state of the Taskbar progress bar is set by the value in the ComboBox which lets you notify the user with different colors about the state of the activity.

As you can see, these three features are quite simple to create and you can add them into your .NET applications with the minimum of effort, yet offer a great new user experience to your end customers. Next month we'll take a look at more such stuff that lets you do tasks easily in Windows 7.

tech-news