Archive for August, 2007

Code Camp Boot Camp 2007

Sunday, August 26th, 2007

New Zealand Code Camp logoAs part of the New Zealand .NET User Group I am helping organise a Code Camp event in Christchurch later this year.

The theme is “next generation, back to basics”, i.e the 2 day event will be filled with presentations looking at the upcomming releases of C#, VB.NET, .NET 3.5, ASP.NET, and SQL Server, with a focus on how to get up to speed on them quickly.

More details can be found on the NZ .NET User Group website at www.codecamp.net.nz. The exact date has not yet been determined, but will be a Saturday and Sunday during November (depends upon venue availability). In the mean time it would be helpful if people who are interested could pre-register on the website to allow us to guage the likely number of attendees.

Further details can be found on Peter’s blog.

Updated Windows Mobile 6 SDK Documentation

Tuesday, August 14th, 2007

The Windows Mobile 6 SDK documentation has recently been updated on MSDN. The new documentation includes a couple of new navigation features which hopefully will make the documentation more discoverable and easier to navigate.

I particularly liked the topic index, which seems to be the work of John Kennedy. His recent posting discusses what’s changed since the last release.

The other thing which has started in the last few months is Jim Wilson’sHow Do I?” webcast series. These appear to be worth keeping an eye on. I like the fact that each video is a bite size tip which covers one topic/problem in depth.

Determine which version of the .NET Compact Framework is in use

Monday, August 13th, 2007

Yesterday I outlined how an end user can determine which version(s) of the .NET Compact Framework are installed on a device. Sometimes it can be useful to query which specific version of the framework an application is currently running on. This could be used for instance, in automated bug report forms to provide your support staff with an accurate picture of the environment your application is being utilised within.

Within an application you can simply query the Envrionment.Version property to determine the version of the CLR your application is running on, for example:

MessageBox.Show(Envrionment.Version.ToString(), "CLR Version Number");

The version property is an instance of the System.Version class. To check if your application is running on a specific version of the .NET Compact Framework you can construct an instance of the Version class to represent the desired version number (see yesterday’s entry for a table) and perform a simple comparision, as the following example demonstrates:

Version targetVersion = new Version("2.0.7045.0");
if (Envrionment.Version == targetVersion)
     MessageBox.Show("You are running .NET CF 2.0 SP1", "Status");

Windows Mobile Tip: Determine which versions of the .NET Compact Framework are installed

Sunday, August 12th, 2007

Windows Mobile devices can come with different versions of the .NET Compact Framework installed in ROM. End users can also install various service pack releases etc. This blog entry outlines how in customer support scenarios you can determine which version(s) are currently installed on a particular device.

Overview
The .NET Compact Framework installs a utility called cgacutil.exe onto each device. This utility is primarily designed to allow the addition or removal of assemblies from the .NET Compact Framework’s GAC (see the section titled “The GAC” within Richard Grimes’s Fusion Workshop article for further details).

The utility however also has a handy feature which enables you to determine which version(s) of the .NET Compact Framework are currently installed.

How to run cgacutil.exe
On Pocket PC or Smartphone devices you can use the File Explorer application to navigate to the \Windows directory. Within this folder you will find the cgacutil.exe application which you can launch by tapping on it. As an alternative you could use the run dialog tip I mentioned earlier by typing “cgacutil” into the run dialog.

Once cgacutil is started a popup message box will appear which will list the version numbers of currently installed version(s) of the .NET Compact Framework.

Picture of message box displayed by cgacutil application showing which versions of the .NET Compact Framework are installed

If more than one version of the .NET Compact Framework is installed, these will be listed in a comma separated list.

Comparing .NET Compact Framework version numbers to releases
To convert the version numbers reported by cgacutil into the names of the co-responding .NET Compact Framework releases you can compare them to the following table:

Release Name Version Number
1.0 RTM 1.0.2268.0
1.0 SP1 1.0.3111.0
1.0 SP2 1.0.3316.0
1.0 SP3 1.0.4292.0
2.0 RTM 2.0.5238.0
2.0 SP1 2.0.6129.0
2.0 SP2 2.0.7045.0
3.5 RTM 3.5.xxxx.0

This table contains all current versions of the .NET Compact Framework. I however have not included any BETA or CTP (Community Technology Preview) releases as these are generally found only on devices owned by developers.

The .NET Compact Framework v3.5 has not been released to manufacture (RTMed) yet. Hence the exact version number is not known at this time. The entry in the table above is only for indicative purposes only, I do not know which digits will replace the xxxx part of the version number at this stage.

.NET Compact Framework presentation links

Wednesday, August 8th, 2007

A big thank you for all those that turned out for my presentation at the Christchurch branch of the New Zealand .NET User Group. There was quite a large turnout, and I hope that you all found some value in my presentation.

This was my first presentation of any form, and it was a very useful learning experience. I have defiantly learnt some things which will help improve future presentations I may present. I would be interested in hearing any feedback you may have on my presentation (good or bad), both in content and the way it was presented.

For those that could not make it (I know there were a few), I have uploaded the powerpoint presentation to www.slideshare.net. During the presentation I mentioned that I would provide a list of related website references for the various topics and products discussed, these have been attached to the bottom of this posting.

If anyone would like to discuss Windows Mobile development topics (native or managed), please feel free to get in contact with me. For development problems I would suggest trying the MSDN Forums website, as there are a number of active participants found there (including myself).

The Device Landscape

Development Environments

.NET CF – Platform Support

Screen Differences

Image Capture
Remember that these classes can be used in both .NET CF 1.0 and .NET CF 2.0 applications. They are however only present on Windows Mobile 5.0 or higher devices.

Network Communications
Disconnected Service Agent – a way to “cache” web service method calls when disconnected from the network and to automatically execute them when the connection comes back. See Smart Client Software Factory links below for the full documentation, or see the following post on MSDN forums for a brief overview.

Data Access

Development Tools

Getting Started

Diving Deeper

Where to get help

Reminder: Introductory Compact Framework Presentation

Monday, August 6th, 2007

Picture of a projectorJust a quick reminder that the presentation I mentioned previously is on this Wednesday night. The topic of my presentation is “Introductory Compact Framework Development”.

Further details can be found on the New Zealand .NET User Group website. Please register, as numbers are used to determine how much beer and pizza is required.

Presentation Summary

The internet has helped to shorten the distance between countries.

Likewise mobile computing has started to extend the reach of the office out into the field. The .NET Compact Framework is the .NET based platform for developing software for mobile workers utilising Windows Mobile based PDAs. This presentation will introduce the capabilities and history of the platform as well as providing lots of tips and tricks on how to develop your own applications.

Come along to find out what the difference between Windows Embedded CE and Windows Mobile is. Why the WinPad project failed, or simply to learn how to develop for this exciting platform.

About the presenter:
Christopher Fairbairn has spent the last 7 years specialising in software development in the mobile environment. He currently works for ARANZ Medical Limited in the Christchurch CBD. His current personal project is porting Google Gears to the Windows CE platform.

I hope to see some of you along at the Canterbury Innovation Incubator this Wednesday at 5:30pm.

Programmatically create and display Notifications

Thursday, August 2nd, 2007

Screenshot showing an example popup notification on a Windows Mobile 6 Professional deviceThe Windows Mobile operating system provides a Notifications feature which can be utilised to display prompts to the user in the form of toast or popup balloons (depending upon operating system version) even when your application is running in the background. These are ideal for when your application must inform the user that background tasks have completed, or that particular actions must be performed. This blog entry discusses how you can utilise notifications within your own applications.

Supported Platforms
Notifications are only supported on Windows Mobile Professional or Classic (i.e. Pocket PC) devices, they are not supported on Windows Mobile Standard (i.e. Smartphone) devices. If you develop a Compact Framework application which uses notifications, the application will compile when you target a Windows Mobile Standard device, but will cause a NotSupportedException when the application is ran on the device.

To utilise the Microsoft.WindowsCE.Forms.Notification class you must add a reference to the Microsoft.WindowsCE.Forms.dll assembly.

One of the easiest ways to obtain this reference, and to configure your notification is to drag a “Notification” component from the Toolbox within Visual Studio 2005 (it is located within the Device Components category). Doing this will automatically added the needed reference to your project, and allow you to configure the notification’s properties graphically via the Properties window.

Notification Properties
The notification class has a number of properties which control the look and feel of the notification balloon. These properties are as follows:

  • Caption – the text displayed in the caption bar at the top of the notification balloon.
  • Text – a string containing the HTML content to display in the main part of the notification popup. This enables you to use formatting, and different colours within your notifications.
  • Critical – a boolean flag, if set to true this indicates that the notification is of urgent importance. This has the effect of using a different colour border around the edge of the notification.
  • Icon – The icon to display on the nav bar for the notification. The user can tap on this icon to display a hidden notification, so it should be representative of the meaning of the notification.
  • InitialDuration – the number of seconds the notification should appear on the screen when initially made visible. After this duration has expired the notification will hide itself, and the user will have to tap on the icon on the nav bar to make it re-appear. If this value is set to zero the popup notification is not displayed, instead going straight to the icon on the nav bar.
  • Visible – setting the Visible property to true, will make the notification balloon appear on the screen.

Displaying a notification
To display a notification to the user is as simple as creating an instance of the Notification class, setting up the properties for the desired effect, and then finally setting the Visible property to true to make the notification visible to the user. This is demonstrated in the following sample:

using Microsoft.WindowsCE.Forms;
 
private Notification n = null;
 
private void button1_Click(object sender, EventArgs e)
{
  // Create an instance of the notification class and configure
  // its properties for the desired effect.
  n = new Notification();
  n.Caption = "Hello World!";
  n.Text = "<b>This</b> is a <u>sample</u> notification!";
  n.Critical = false;
  n.Icon = Properties.Resources.NotificationIcon;
 
  // Finally to make the notification appear on screen
  // set the Visible property to true.
  n.Visible = true;
}

One important thing to notice is that we have not used a local variable within the button1_Click method to hold the Notification we are displaying to the user. The reason for this has to do with the CLR and its Garbage Collection behavior. Although the code may work if you use a local variable, it is not guaranteed and will potentially lead to unpredictable behavior (more on this in a later section).

The only property which deserves further discussion is the Icon one. You can store an icon in a number of ways. Perhaps the easiest way to store an icon in your executable is to use the Resources.resx file the Visual Studio 2005 project wizard will have created for you. The following screenshot demonstrates where you can find this file within solution explorer. If you open the file you can add new icon(s) into it, and these icons will be accessible via strongly typed properties within the Properties.Resources class, as demonstrated by the code sample above.

Screenshot of Visual Studio 2005 demonstrating how to find the Resources.resx file to include the icon resource

Hiding a notification
There are two different ways you can remove a notification which is visible on the screen.

You can simply set the Visible property to false, as the following example demonstrates:

// Using this approach to hide a notification will allow you
// to re-display it by changing the Visible property back to true.
n.Visible = false;

This has the benefit that you can decide to re-display the notification, by simply resetting the Visible property back to true. You can change the Visible property as many times as you like.

The alternative approach is to call the Dispose method of the Notification class, as the following example demonstrates:

// Using this approach will hide the notification but won't
// allow you to re-display it without creating a new instance
// of the Notification class.
n.Dispose();

Once you have done this you will not be able to display the notification again, without creating a new instance of the Notification class.

Previously we mentioned that you should not use a local variable to reference your Notification object. This last code sample demonstrates the reason why. If you had stored your notification in a local variable within the button1_Click method, the garbage collector would detect your variable as potential garbage when the method completed. If a garbage collection occurred, and decided to collect this reference, the garbage collector would call the Dispose method on the notification, which would remove it from the screen. By keeping a reference to the notification “alive” for the life time of the form (by using a member variable to reference it) the garbage collector will not be able to dispose of it until the form is closed.

Detecting when the notification is hidden
The notification class has a BallonChanged event which fires whenever the notification balloon is made visible, or hidden.

The following example, demonstrates how you can listen to this event, in order to perform a task when the popup balloon is hidden:

Notification n = new Notification();
// configure the notification properties...
n.BallonChanged += new BallonChangedEventHandler(n_BallonChanged);
 
void n_BalloonChanged(object sender, BalloonChangedEventArgs e)
{
  // The Visible property indicates the current state of the
  // popup notification balloon
  if (e.Visible == false)
  {
    // If the balloon has now been hidden, display a message box
    // to the user.
    MessageBox.Show("The balloon has been closed", "Status");
  }
}

Sample Application
Screenshot of sample applicationA sample application is available for download, which demonstrates the use of the Notification class. It enables you to experiment with the various properties of the notification class, and see how they alter a notification.

There is one member of the Notification class which we have not discussed in this blog entry. This is the ResponseSubmitted event which can be used to process feedback provided by the user when they dismiss the popup notification. For example in the HTML text of a notification, you could create a couple of radio buttons, and a text field. By handling the ResponseSubmitted event you can determine what values the user has entered and use them to alter the behavior of your application. Covering how to utilise the ResponseSubmitted event to process HTML based forms will be the topic of a future blog entry.