DNUG Meeting: The Zen of Inversion of Control

May 15th, 2009
Photo of Christopher Fairbairn
Date: Wednesday May 20th 2009
Time: Gather at 5:30 pm, starting at 6:00 pm
Location: Canterbury Innovation Incubator
Presenter: Christopher Fairbairn

Heard of the concepts Inversion of Control and Dependency Injection, but not quite sure what they are or how they can be applied to your day to day coding? Then this demo filled presentation is for you!

Learn from one beginner’s journey to better understand the fundamentals, without feeling the need for a dictionary to translate all the foreign terms and concepts that inevitably come about.

And even if you’re a Dependency Injection guru, you may learn a little background knowledge of new languages features introduced in C# 2.0 and C# 3.0 that make things easier to implement.

Making auto suggestions more appropriate for your textbox

May 1st, 2009

Screenshot showing the textbox providing a list of suggested phone numbersTo round out my coverage of Input Contexts we need to cover the concept of Input Classes. Put simply an input class is a hint to the Windows Mobile OS as to what kind of information should be entered into a text box (for example an email address, phone number, or person’s name).

Selecting an Input Class for a textbox will change the source of data used for the auto suggestions provided by the OS as the user starts typing. For example in the screenshot above you can see the user is typing in a person’s name yet the operating system is suggesting matching cellphone numbers.

To specify the Input Class for a textbox we can use the native SHSetInputContext API and set the SHIC_FEATURE_CLASS feature. Yesterday’s code sample provided a suitable wrapper around this API for this purpose.

Sample Application

[InputContextSendSMS.zip - 10.8KB]

To demonstrate the use of Input Contexts I decided to make a modified version of the SendSMS application I presented earlier. In this modified version when a user starts to type in a person’s name into the phone number textbox the operating system will provide suggested phone numbers based upon data found within Pocket Outlook’s contacts list.

The code changes required to the original sample application were minimal and consisted of the following two lines of code which use the InputClass developed yesterday.

// Setup the input context for the phone number text box
// so that it will provide auto suggestions of phone numbers
// associated with outlook/SIM contacts.
InputContext.SetClass(txtPhoneNumber, InputContextClass.Phone);
InputContext.SetHaveTrailer(txtPhoneNumber, false);

The call to SetHaveTrailer means that if the user selects a suggestion from the popup list the OS will not automatically insert a seperator character. If you set this feature to true a semicolon would be inserted allowing the user to quickly create a list of two or more recipients.

Programmatically set Input Context features

April 30th, 2009

In my last blog post I discussed how an end user could change word completion features at a system wide level. This blog post covers how a .NET Compact Framework developer can programatically change the behaviour on a textbox by textbox basis.

The Windows Mobile operating system provides a function called SHSetInputContext that enables a developer to configure the various properties of the input context associated with a given control.

By using a DllImport declaration we can gain access to this native function from our C# application as shown below:

using System.Runtime.InteropServices;
private enum SHIC_FEATURE : uint
  CLASS = 4
private static extern int SHSetInputContext(IntPtr hwnd,
  SHIC_FEATURE dwFeature,
  [MarshalAs(UnmanagedType.Bool)]ref bool lpValue);

Once declared it is as easy as passing a boolean true or false value to SHSetInputContext along with the name of the input context feature we want to configure.

For example to disable auto suggestion for a textbox called “textbox1″ we could use the following code snippet:

bool value = false;
  ref value);

Sample application

[Download InputContextDemo.zip - 10.6KB]

A sample application is available for download. It wraps up the calls to SHSetInputContext into a handy InputContext class that can be re-used within your own applications.

The sample application has a single textbox and a series of checkboxes. The checkboxes enable you to control the various input context features present within the Word Completion tab of the Input control panel applet for the textbox.

We’ll round out our discussion of Input Contexts by covering Input Classes within the next blog post. In the mean time see if you can determine what changes in behaviour occur when you select the various options within the Input Class combo box.
Screenshot of sample application demonstrating setting Input Context features

Windows Mobile Tip: Word Completion settings

April 23rd, 2009

Screenshot showing location of Input control panel applet and the Word Completion tabAnother Windows Mobile feature that is commonly undiscovered are the word completion settings. You can find these within the “Input” control panel applet, found within the Personal tab of the Settings application.

Although the labeling and precise set of options available changes with Windows Mobile version you should be able to configure the following types of word completion features:

  • Suggest words when entering text: Should Windows Mobile suggest possible ways to complete the word currently being entered via a popup list.
  • Add a space after word: Should a space be automatically inserted if the user selects a word from the word completion list.
  • Enable auto correct: Should common typing mistakes such as typing “youre” when you meant “you’re” be corrected automatically when typing a space after the word.

Enabling the Auto Correct feature is more practical for English speakers than it is for other users of other languages. The rules and auto corrections are rather hardcoded and may interfere with phrases common in other languages. You may spend more time correcting the auto corrections than it spends correcting your mistakes!

Now for the bad news… your mileage may vary with this Windows Mobile Tip. Although the word completion feature is a standard part of the operating system there are a number of “moving parts” between the keyboard and the application which could affect text input behavior. Altering these settings on your particular device may or may not alter the word completion behavior of your device, as word completion may be implemented or controlled by another part of the software stack (for example a custom Software Input Panel developed by the device’s OEM).

Tomorrow we’ll discuss how a .NET Compact Framework developer can programmatically control these word completion features on a textbox by textbox case.

Visual Studio Tip: Import a *.reg file

April 22nd, 2009

Screenshot of Visual Studio IDE showing the Registry Import menu item

Here is a handy feature of Visual Studio which took me a while to discover when I started using the tool.

As part of packaging up an application it is common to store configuration settings within the registry. While using a Smart Device CAB project you can use the convenient Registry view to set up these values graphically.

The feature that I didn’t notice for a while is the fact that you can right click on the window to get an Import… menu item (as shown in the screenshot above). This enables you to import a group of settings from a *.reg file, which saves you manually entering them all via the IDE.

So how do you create a *.reg file? One way is to manually write one in a text editor. Another is to generate it via the Windows CE Remote Registry Editor utility. Once you have configured your device you can use this tool to export a specific sub-tree of the device’s registry as a *.reg file that you can then import directly into Visual Studio.

Screenshot of Windows CE Remote Registry Editor utility showing the Export Registry File menu option

DNUG Meeting: SQL Server 2008 New Features tour

April 20th, 2009
Photo of Rob Hawthorne
Date: Tuesday April 28th 2009
Time: Gather at 5:30 pm, starting at 6:00 pm
Location: Canterbury Innovation Incubator
Presenter: Rob Hawthorne

SQL Server 2008 delivers on Microsoft’s Data Platform vision by helping your organization manage any data, any place, any time.

This new release builds on the great platform laid with SQL Server 2005, enhancing it with great new capabilities such as native support for spatial data, database encryption and compression and enhanced manageability through Policy Based Management, Powershell and the Resource Governor as well as many new great enhancements for Analysis Services and Reporting Services.

Come join us for the Christchurch stop of this national tour, as we delve into the new features of SQL Server 2008 and the benefits they can bring to your organisation.

TechDays 2009 – April 1st – Defy all challenges

March 23rd, 2009

What will you be doing on April the 1st? As a developer you should be planning to be part of Microsoft’s TechDays 2009 event. This 24 hour event is a series of live and recorded webcasts that slowly moves around the virtual globe. It’s a chance to learn with more than 95 technical sessions on current and merging technologies in mobility, Windows, Office, Sharepoint and Web development. It’s also a unique opportunity to meet and connect with Microsoft employees and industry experts alike.

It’s also my first oppertunity to present a webcast for Microsoft. During the event I’ll be presenting two great presentations originally developed by Paul Yao and Alex Yakhnin as the event rolls through my timezone.

You can view a constantly updated list of sessions for further details. Including details on the two presentations I will be presenting.

  • MBL201a Win32 versus .NETCF: The Right API for Your Job – The Windows Mobile platform offers two core APIs. Each has its strengths and situations when one makes sense over the other. This session provides a framework for selecting which API makes sense, when it makes sense, and why each choice makes sense for the given scenarios. This session provides details that will ensure that you never feel at a loss when encountering this question.
  • MBL400a Creating Compelling and Attractive UIs for Windows Mobile Applications – In this webcast, we explain how to utilize the Alpha blending and Gradient drawing APIs on the Windows Mobile platform to create a compelling and attractive user experience in your mobile applications. We also provide an example of how to create a framework that could be used to simplify the development of custom user interfaces.

Make sure you register today!

Community Interview: Peter Vrenken

January 19th, 2009

Photo of Peter Vrenken1) Can you introduce yourself?

My name is Peter Vrenken and I am a 30 year software engineer happily living with my girlfriend in the east of the rainy Netherlands (the city of Almelo to be precise).

I call myself a “software gadgeteer” (sometimes also referred to as a geek :-)). I’m not only interested in Windows Mobile development but also other kinds of software technology such as artificial intelligence, user-interface theory, software development tools and innovation such as PhotoSynth, Panoramio, and Google Gears.

2) Who do you work for?

At the moment I’m working as a Mobile Software Engineer for Sigmax Mobile Solutions (located in Enschede). I work in a team that develops law enforcement and supervision solutions. One of my tasks involves the development of new features for the mobile application and its user-interface. And no, adding a new skip-my-parking-ticket feature is not allowed!

I am also studying towards a Masters in Philosophy of Science, Technology and Society at the University of Twente. I have written my thesis on how end-users more and more influence the development of mobile software appliances. Mobile devices are starting to grow out of their child-age and are steadily throwing off their gadget-image to become the mobile tools we want them to be.

3) How did you become involved in Windows Mobile based development?

To finish my Bachelor in Software Engineering I had to do a project for Pemstar B.V. (now known as Benchmark Electronics). One of the new products they were developing was based on an Intel PXA255 hardware platform running Windows CE 3.0. I developed a stress-test tool which could test the different hardware device drivers of the platform. The result of this research was a working set of desktop and device tools written in C# and native C++ that worked together and could be scripted. It was the first time I had worked with both .NET and mobile hardware, and was truly a great project to work on.

4) When did you start developing your own personal applications?

Researching the stress-test environment for Windows CE increased my affinity with these devices, and as a developer I just cannot seem to use a piece of hardware without fiddling around with it and finding out how it works. I see the development of mobile consumer software as a hobby, but my girlfriend calls it a curse whenever I try to write some software to tweak and tune a device she uses!

5) One of the applications that you offer for sale from your website is called MusicAlarm. How did this come about?

MusicAlarm started out with me being jealous at all non Windows Mobile phones that can awake you in the morning by playing a nice song. I got annoyed with the horrific sounds available on a Windows Mobile device and the complex configuration of the standard alarm application.

To be precise my girlfriend got annoyed of me not being able to quickly stop the alarms from playing. This got me thinking about how an alarm application should work. The result is MusicAlarm, which can be downloaded from my website.

6) What is your preferred development environment?

I have really grown fond of C#. It is a very powerful language that is still easy to understand, while being flexible enough when complexity kicks in. For example the Platform Invoke feature comes in handy accessing Windows Mobile specific functionality not exposed by the .NET Compact Framework.

As a development tool Visual Studio 2008 rocks!

7) A number of your applications have fairly custom looking user interfaces. How challenging is it to develop rich user interfaces using the existing tools?.

Very challenging. Out of the box the tools within the .NET Compact Framework only allow the most basic looking applications that conform to the guidelines set out by Microsoft. Radical deviations required for complex user interfaces are not easily realised.

Customisation of built in controls is very limited and when more advanced GUI features are required the .NET Compact Framework sometimes really hinders development.

As an example take the simple situation of drawing text on a picture or gradient background.. This problem is something which a lot of people come across during development (just read the support forums) and requires some kind of transparent label. On Windows Mobile the inner workings of windows controls limit the realisation of such a label, which results in a lot of weird workarounds and incomplete patches being proposed.

8) Do you carry a Windows Mobile device with you at present?

Yes I do, at the moment an HTC Kaiser, which is also used for development and testing purposes. Sometimes – like on vacation – I also carry my old HTC Wizard, but mostly so that my girlfriend can play a game of Bubble Breaker :-)

9) If you had the choice of having one feature implemented in the next release of Windows Mobile what would it be?

I really like the diversity of the hardware Windows Mobile is available on. There is a device to suit every person’s preference.

However, I think the Windows Mobile platform misses out on features that are required to make stunning user interfaces. Take for example the Win32 or GDI+ APIs. The versions that can be used on devices are only limited subsets of those available on desktop machines. The hardware and operating system are fast and powerful enough to allow applications to be enhanced by fancy graphics and animated effects, but the available APIs make it less than straight forward.

The look and feel of a Pocket PC 2003 devices just looks like a mini version of Windows 98. If devices such as the Apple iPhone or HTC devices with TouchFlo user interface demonstrate anything it is that mobile devices do not need to carry desktop specific user interfaces and metaphors.

This leads me to the conclusion that Microsoft would do great on rethinking the requirements of a mobile user-interface. It wouldn’t surprise me if a technology such as Silverlight will be the start of a move in this direction.

Until then developers like myself will try to make the best of it by cooking our own user interface APIs and frameworks.

10) If you had one thing to say to potential developers what would it be?

Keep faith and don’t forget to interact with the community. Developing advanced Windows Mobile applications can be very tedious but very satisfying. The Windows Mobile community has some very nice forums and websites where loads of information can be found.

Windows Mobile development sometimes requires advanced know how and alternative techniques (I like to call it voodoo :-)).

The forums like the ones found on MSDN really can make a difference when you know where and how to search for information. Also don’t forget to review some of the available webcasts and videos.

DNUG Meeting: From nUnit to Awesome Rock Song

January 14th, 2009
Photo of Dave Mateer
Date: Wednesday 21st January 2009
Time: Gather at 5:30 pm, starting at 6:00 pm
Location: Canterbury Innovation Incubator
Presenter: Dave Mateer

In his mission to become a great developer, Dave will entertain you with ‘From nUnit to Awesome Rock Song’. Dave will demonstrate the time and heartache savings (which allowed time and energy to do the music).

Tools and technologies (ab)used in this talk will include: C#, .NET 3.5 SP1, VS2008 Express, PHP, JSON, MySQL, and nUnit. Dave will demo the Awesome Rock Song too!

If you’ve heard of unit testing, this presentation is for you. Bring your laptop along and take away your first working unit test project. Your future development projects will be easier!

Programmatically changing the Device Name

December 15th, 2008

Screenshot of Set Device Name applicationFor some Line of Business (LOB) applications intended for tightly controlled deployment environments you may want to programatically set the Device Name of each PDA. This blog post discusses one common technique for achieving this.

Changing the Device Name

A Windows Mobile device stores the Device Name in the registry underneath the HKEY_LOCAL_MACHINE\Ident\Name value. This means we can make use of the Microsoft.Win32.Registry class to change the value and hence update the device name.

A code snippet for achieving this could take the following form.

using Microsoft.Win32;
void SetDeviceName(string deviceName)
  // Change the device name of the current Windows Mobile device
  using (RegistryKey key = Registry.LocalMachine.OpenSubkey("Ident", true))
    key.SetValue("Name", deviceName);

Verifying the change

The device’s TCP/IP stack utilises the device name as the device’s hostname. So an easy way to verify that the change has been successfully made is to ask what the current hostname is. This process is demonstrated below.

// Determine the current host name
using System.Net;
MessageBox.Show(Dns.GetHostName(), "Current Device Name");

Be aware however that certain parts of the operating system may require additional steps to be taken in order for them to read the updated information stored in the registry. Refer to the article titled “Naming a Device” available on MSDN for additional guidance.

Sample Application

[Download setdevicename.zip - 9.64 KB]

A small sample application is available for download. It demonstrates setting the device name programatically and includes two buttons to enable the user to verify that the change has been correctly made.

The first button asks the DNS subsystem for the current host name, while the second makes use of a technique discussed previously to display the Device ID control panel applet.

Another way to verify the change has been made is to simply connect the PDA to your desktop PC via ActiveSync. The main ActiveSync window displayed on the PC should display the device name in the top left hand corner.