Nick's .NET Travels

Continually looking for the yellow brick road so I can catch me a wizard....

Extending the Widget model on Windows Mobile 6.5

Over the past week we have seen a number of posts from Jorge and the team at Microsoft covering what’s new for developers in Windows Mobile 6.5.  This was kicked off with the release of the Windows Mobile 6.5 Developer Tool Kit which includes both emulators and documentation/samples for working with gestures. 

What isn’t included in the DTK is any documentation on building Widgets. Jorge made a great initial post covering getting started building your first widget but went short of providing any real documentation on the extent of the widget object model. One of the first question that comes to mind is extensibility.  This has in part been answered in a forum question and answer.

The upshot is that in order to extend the widget model you need to build and deploy an activex control that can do the hardwork for you.  If you want to try it out, all you really need are WM6.5 emulator images and the Windows Mobile 5 SDK (that’s right the WM5 SDK!).  In the WM5 SDK you will find a sample called AXSample which surprise, surprise is an ActiveX control sample (On my machine this is in the folder C:\Program Files\Windows Mobile 5.0 SDK R2\Samples\PocketPC\CPP\ATL\AXSample). You can load and run this sample and it will display the simple activex control in the IE Mobile browser (step 1…. done).

The next thing to do is to add the registry value to enable the activex control for use within a widget.  Note that the other registry values mentioned by Jorge are added automatically by Visual Studio when you depoy and run the activeX control sample.  The registry value you need to set includes the CLSID for your activeX control.  You can get this a couple of ways but the easiest is using the Remote Registry Editor:

image

Once you have the CLSID you can go and create the appropriate keys and values:

image

You will note here that I have replaced the <ObjectName> value in Jorge’s answer with “SampleControl”.  This is how we then reference this object from within your widget javascript code:

                var myObj = widget.createObject("SampleControl");
                alert("The current fill color is " + myObj.FillColor);

This is in essence all you need to do in order to extend the widget framework.  This example just shows how you can retrieve a value from the activex control but you could execute any native code you want as part of executing that property.

If you look at the other samples that ship with the Windows Mobile 5 SDK you will notice that there are a host of native code examples on everything from retrieving the current phone number through to accessing POOM.  You can use any of these to build out your widget code to do whatever you want on the device.

Now the downside…. you can’t deploy a widget with an activex control embedded in the widget file via marketplace.  So the question is how you can deploy your widget and still leverage activex controls.  I would suggest the easiest approach is to build the widget so that when it first loads it detects if the activex control is present.  If it’s not, it can direct the user to a download site where you have placed a .cab file with the relevant activex control in it.  Of course, as marketplace has not available yet we don’t know if even this strategy will be possible. 

Comments are closed