Archive for March, 2008

Community Interview: Steve Hegenderfer

Friday, March 28th, 2008

Photo of Steve Hegenderfer1) Who are you? Where are you located?

My name is Steve Hegenderfer. I am a Technical Evangelist, Group Manager for Solutions Delivery within Windows Mobile, all around great guy…located out of the Mothership, in Redmond WA.

2) What does the Solutions Delivery group within the Windows Mobile unit do?

My new role is running what we are calling Solutions Delivery within Windows Mobile. I focus on the enterprise and business side of things. Think of it like this; we have a lot of things we want to build as MS, but we can’t (nor do we want to) build all of them. My group’s job is to go out, find 3rd party solutions to fill those needs, and take them to market with us.

3) What does this job involve?

Wow…what does the job NOT involve :)

I’m still active with the blogs (my partner in crime is Reed Robison); but, that’s more something I really like to do to send out some info and thoughts. My team is actually pretty cool. You can think of it as a microcosm of the larger MS. We have folks on my team that look at the market and the needs, and go out and find partners to fill those needs. We have folks on my team that work out the business plans (who gets paid what and when and how we split the pie). We also have some people who work on the go to market materials and the integration with our field and the mobile operators’ sales force. So, we have the full gamut.

And, I’m hiring :)

4) What did you do before working for Microsoft with Windows Mobile?

Wow, what DIDN’T I do :) Funny, I spent about 10 years going from start-up to start-up, mostly in the San Jose, CA. area. I would just keep going from job to job, doing things that really interested me. That’s one of the reasons I ended up here at MS; and I have no plans on leaving THIS group any time soon…too much cool stuff going on :)

5) So how did mobile devices catch your eye and keep your attention?

Kinda funny…I used to develop old WAP apps on the first few wireless Palms that came out. But it really started when I read an article about how Reebok was using embedded systems in some of their shoes. I thought, “Man, that is some seriously cool stuff…think of the possibilities!”

One thing led to another, and here I am.

6) It’s been announced that MEDC2007 was the last Mobile and Embedded Developers Conference (MEDC) event, and that from 2008 onwards MEDC content will be rolled into two streams of the Tech·Ed conference. Is this a sign that mobile device development is becoming more mainstream, or is it more the case of there not being enough support for a standalone event?

This is a good thing. It means that mobility is going main-stream. I talk to HUGE enterprise customers all the time, and by a long shot they are ALL asking how they start doing this stuff; how can they extend their existing assets and infrastructure into the mobile world.

MEDC was more like preaching to the converted; don’t get me wrong, we still need to, and will be. But we need to take the message broader to more folks who are interested in this, who wouldn’t necessarily go to MEDC, but do go to Tech·Ed et al.

So, in the end, while I WILL miss MEDC, this is a good thing.

7) How can small Windows Mobile ISVs best engage with Microsoft?

First of all, look at joining the Microsoft Partner Program (MSPP) at the certified or gold level. And take a look at the ISV competency within it; there is a mobility skew to it if you don’t think that the Windows Mobile specific Mobility Solutions competency is the right one for you. So, step one, get in there.

8) You seem to be excited about the possibilities the new System Center Mobile Device Manager (SCMDM) application offers enterprises deploying mobile devices. What is this product and how does it help enterprises deploying or developing Windows Mobile based solutions?

MDM is actually VERY cool. It provides security to the device (device-side encryption as well as SD card encryption/white and black listing, etc,), the ability to manage the device (think asset/inventory/policy/etc). But one of the coolest features for the business developer is an always-on mobile VPN that makes accessing all of your company’s assets securely for your apps a cake walk.

9) SCMDM is arguably a business oriented feature, and enterprise mobility has always been a main stay of the Windows Mobile platform. Do you think with the announcement of devices such as the Sony Ericsson Experia X1 that Windows Mobile is also starting to make inroads into the consumer market?

That is a loaded question :) I think the X1 is more of a business device (even though it’s sexy as all get out). But, we ARE focusing on the consumer and the experience that those individuals have. Expect more devices like the X1 and more experiences like that in the future.

10) Do you carry a Windows Mobile powered device with you? If so what feature couldn’t you live without, and if you had to pick one feature it had missing (or was less than ideal) what would it be?

I do, in fact! I carry it with me everywhere. There are a few things that I love, but access to push email via Exchange is one of the tops; now that we’re dog-fooding MDM, access to some of the apps we are rolling out internally is very cool.

One missing feature…hmmm…I think it might be something more compelling in the interface. Having said that, the horizon is near for some of those features as well :)

11) If you had one thing to say to potential developers of Windows Mobile applications what would it be?

Just start doing it. If you know VB, C#, or C++, and are familiar with Visual Studio, you already know the essentials of developing for Windows Mobile. Sure, the memory and form-factor constraints are there, but you will get a feel for those over time. The emulators are decent, and the SDK is good, so you should just hop in with ‘Hello World’ and then go from there…if I can develop for the platform, ANYONE can :)

Some folks say it’s too difficult to develop for Windows Mobile…I say rubbish, you just have to watch yourself and make sure you are doing the right things.

12) Any predications for 2008?

Being an insider, I’m not sure I can make any predictions for 2008 :)

I will say that this space is REALLY heating up; more players, cooler devices, better HW in general…and MS will be right there in the thick of it. Personally, I am VERY excited for WM in 2008 and 2009…you should all be prepared for some nice innovation in both the business world and the consumer world!

Windows Mobile Tip: Creating shortcuts

Thursday, March 27th, 2008

Shortcuts are small files containing the location of another file, or the command line required to launch an application. They are commonly placed within the Windows Start Menu as a convenient way to access common functions of your device. By creating and organising your own shortcuts you can customise the features you have quick access to on your device.

Creating a shortcut

You can create shortcuts directly on the device by using the built in File Explorer application. In order to create a shortcut first navigate to the file you want a shortcut for and tap and hold the stylus over the file to display a context sensitive popup menu. From the menu select the “Copy” option.

Now navigate to the location where you want to place the shortcut and tap and hold the stylus over a blank area (such as after the last file in the directory listing). This displays a similar context sensitive popup menu from which you can select a “Paste Shortcut” option.

A shortcut to the file will be created. By default the newly created shortcut will have the name “Shortcut to XYZ” where XYZ was the original file name. By using the standard file rename functionality you can rename the shortcut to a more suitable name.

Uses of shortcuts

Shortcuts are used within the Windows Mobile operating system for a wide range of purposes. By placing your shortcuts into specific folders you can obtain special functionality. Some examples include:

  • \Windows\StartUp – shortcuts to applications placed in this directory will automatically be started whenever the Windows Mobile device is reset.
  • \Windows\Start Menu – shortcuts placed in this directory will appear in the Windows start menu.
  • \Windows\Start Menu\Settings – as discussed in a previous blog entry shortcuts placed in this folder will appear on the System tab of the Settings application that is accessible via the Start Menu.

Early adopters of the Pointui shell replacement for Windows Mobile devices are using similar techniques to customise the functionality of the built in menus to launch phone dialler applications etc.

Technical Details

Behind the scenes File Explorer is creating a shortcut file (probably via the SHCreateShortcut API). A shortcut is a file that has the extension *.lnk and contains details of the command line or file that the shortcut should open.

Pavel Bánský discusses in his blog the technical details on the contents of a *.lnk file. As an alternative to creating the shortcut file manually, you can also utilise an API called SHCreateShortcut as shown below:

using System.Runtime.InteropServices;
 
[DllImport("coredll.dll")]
public static extern void SHCreateShortcut(
  string target,
  string shortcut);
 
// Create a shortcut to tmail.exe within the
// windows start menu.
SHCreateShortcut(
  @"\windows\start menu\programs\my email.lnk",
  @"\windows\tmail.exe");

Shortcuts can also be created as part of a CAB file installation package for your applications, as discussed in the .NET CF Deployment section of the Microsoft Visual Studio 2005 Professional Guided Tour.

Shortcuts can also have other purposes, one of these I will discuss in greater depth in a future blog posting…

Visual Studio Tip: Open containing folder

Wednesday, March 26th, 2008

A handy feature while editing files within Visual Studio is to open up a Windows Explorer window for the folder that contains the selected file (perhaps to rename a set of files, or to change the attributes etc). This feature has been within the Visual Studio IDE for a few revisions. The easiest way to access it is to open a file in the editor, then right click on the file’s tab and select the “Open Containing Folder” menu option.

Extended Functionality

One problem with this feature is that it requires the file to be opened within the editor in order to be able to right click on its tab. For forms and other project files with complex editor behaviour it can be a timely exercise waiting for the file to load into the editor just to be able to right click on it.

A handy solution to this problem within Visual Studio 2008 is an add-on called the “PowerCommands for Visual Studio 2008“. This extension, written by Microsoft, adds a set of additional functionality to various context menus within the IDE. The two most relevant to this discussion are the “Open Command Prompt” and “Open Containing Folder” options available while right clicking files within the Solution Explorer window (as seen in the screenshot to the right). This saves needing to load the file within the editor in order to access this option and is a great productivity boost. For more details check out the Visual Studio Extensibility (VSX) team blog. The PowerCommands extension is worth installing for just this feature, but also introduces a range of additional ones you will soon not be able to live without.

Going even further

IDE productivity fanatics and keyboard power users may be interested in the following additional things which may further maximise the use of this feature:

  • You could follow the “How to: Work with Shortcut key Combinations” article on MSDN in order to bind the feature to a keyboard shortcut. The command is “File.OpenContainingFolder”.
  • You could add this feature as a menu item within the Tools menu by following the instructions recently given on the .NET Tip of The Day blog. I for one didn’t think about using Visual Studio environment variables such as $(ItemPath) within this dialog.

If you like these kinds of IDE productivity tips, you might like to subscribe to Sara Ford’s blog.

How to make your ListView columns reorderable

Tuesday, March 18th, 2008

Another finishing touch that I like to see in applications that use ListViews is the ability for the end user to re-order the columns to suit their own preferences. This blog entry discusses one approach for adding this functionality to the ListView control present within the .NET Compact Framework. Although it is difficult to convey in a static screenshot, the screenshot above shows a user dragging the stylus over the header of the listview control to move the position of the “First Name” column.

Obtaining Draggable Columns

The System.Windows.Forms.ListView control is a wrapper over top of the native ListView control. The native ListView control supports the notion of extended styles, which allow various optional features to be enabled or disabled as desired. One of the extended styles is called LVS_EX_HEADERDRAGDROP. If this extended style is enabled the user can re-order the columns by dragging and dropping the headers shown at the top of the listview while it is in report mode.

Although the .NET Compact Framework ListView control does not expose a mechanism to enable extended styles, we can use a technique discussed in a previous blog entry of mine to add or remove the LVS_EX_HEADERDRAGDROP extended style as desired.

private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1000 + 54;
private const int LVS_EX_HEADERDRAGDROP = 0x00000010;
 
public static void SetAllowDraggableColumns(this ListView lv, bool enabled)
{
  // Add or remove the LVS_EX_HEADERDRAGDROP extended
  // style based upon the state of the enabled parameter.
  Message msg = new Message();
  msg.HWnd = lv.Handle;
  msg.Msg = LVM_SETEXTENDEDLISTVIEWSTYLE;
  msg.WParam = (IntPtr)LVS_EX_HEADERDRAGDROP;
  msg.LParam = enabled ? (IntPtr)LVS_EX_HEADERDRAGDROP : IntPtr.Zero;
 
  // Send the message to the listview control
  MessageWindow.SendMessage(ref msg);
}

This method allows the drag feature to be turned on and off for a given ListView control. Notice that this method makes use of a C# 3.0 feature called Extension Methods. The “this” keyword in front of the first parameter means that this method can be called as if it was part of the standard ListView control, meaning the following code snippet will work (assuming listView1 is an instance of the System.Windows.Forms.ListView control).

listView1.SetAllowDraggableColumns(true);

This is pure syntactic sugar, behind the scenes the C# compiler is simply passing in listView1 as the first parameter to the SetAllowDraggableColumns method.

Persisting Column Order Preferences

Once you have reorder-able columns it can be desirable to persist the user’s preferred layout across multiple executions of your application. It would be a pain if the columns always defaulted back to a standard order everytime the form was displayed.

The native ListView control provides two window messages, LVM_GETCOLUMNORDERARRAY and LVM_SETCOLUMNORDERARRAY that can be used to implement this feature. The code sample available for download wraps up these two window messages to allow you to query the current order of the columns by using a statement such as the following:

int[] columnOrder = listView1.GetColumnOrder();
// TODO: save 'columnOrder' to the registry
// or another persistent store

When columns are added to a ListView they are given an index. The first column is column 0 while the second is column 1 and so on. When columns are re-ordered they keep their index value but their position on screen changes. The array returned by the GetColumnOrder function contains the index for each column in the order that they are visible on screen. For example if the array contains the values 2, 0, and 1 it means that the last column (column 2) has been dragged from the right hand side of the listview to become the left most column.

Once we have obtained the order of the columns we can store the data in any persistent storage mechanism such as a file, a database table, or registry key. When the form is reloaded we can initialise the default order of the columns by calling the equivalent SetColumnOrder method with the value we previously saved:

// TODO: should read 'columnOrder' from the registry
// or other persistent store
int[] columnOrder = new int[]{2, 0, 1};
 
listView1.SetColumnOrder(columnOrder);

Sample Application

[Download ListViewExtenderTest.zip - 11 KB]

The sample application displays a list of three columns. While running on a Windows Mobile Professional device you should be able to re-order the columns by dragging and dropping the column headers with your stylus. If you exit and restart the application you should see that your custom column ordering is persisted. Via the left soft key menu item you can select an option that will disable the user from re-ordering the columns.

Most of the magic occurs within a file you can reuse in your own applications called ListViewExtender.cs. The sample application targets .NET CF 3.5 and hence requires Visual Studio 2008. With minor tweaks the source code would also be usable within .NET CF 2.0 projects. I would be keen to hear what your thoughts are about this. Is it time to shift code samples to .NET CF 3.5/Visual Studio 2008 or are you still wanting .NET CF 2.0 and Visual Studio 2005 compatible samples?

Create a SQL Server 2005 Compact Edition database by using Query Analyzer 3.0

Wednesday, March 12th, 2008

Screenshot of Query Analyzer about dialog boxSQL Server 2005 Compact Edition Query Analyzer is a small application that can run directly on a Windows Mobile PDA and allows you to create and manipulate SQL Server Compact Edition databases. It is a handy tool to add to your toolbox, as it can help diagnose and correct small database errors while you are away from your development PC.

First a word of warning… Query Analyzer is prehaps the worst application with respect to conforming to the “Designed For WIndows Mobile” logo certification requirements. The application is not supported on Windows Mobile Standard (smartphone) devices, and many dialogs are unusable on small or square resolution Windows Mobile Professional (PocketPC) devices. The application appears to be more at home on devices running the standard Windows CE shell as evidenced by its heavy reliance on non fullscreen dialogs.

Installing Query Analyzer

If your .NET Compact Framework based application makes reference to the System.Data.SqlServerCe assembly Visual Studio will automatically install the query analyser tool when you deploy your project via the IDE.

If you are a native developer or want to utilise the tool without deploying via Visual Studio you will need to manually install the Query Analyzer tool which is part of SQL Server Compact Edition’s developer support cab file.

The SQL Server Compact Edition Books Online documentation has a “How to: Install Query Analyzer (SQL Server Compact Edition)” section that covers this process.

Essentially you need to install the following CAB files on your device:

  • .NET Compact Framework – NETCFversion.platform.processor.cab
  • SSCE runtime – sqlce30.platform.processor.cab
  • SSCE dev tools – sqlce30.dev.ENU.platform.processor.cab

You should be able to find the required CAB files within the %programs%\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\platform\processor\ folder. One tricky bit is the fact that references to “platform” and “processor” in file and directory names above need to be replaced with values specific to the version of Windows Mobile your target device is utilising.

In most cases you can use wce500\armv4i\sqlce30.ppc.wce5.armv4i.CAB and wce500\armv4i\sqlce30.dev.ENU.ppc.wce5.armv4i.cab for Windows Mobile 5 Pocket PC or higher devices. Further instructions can be found in the “How to: Install SQL Server Compact Edition on a Device” article available on MSDN.

One tip to correctly determine the correct CAB files to install is to hard reset a PDA and have Visual Studio deploy your project to the PDA. After the deployment you should be able to refer to the output window to see which CAB files Visual Studio deployed and installed to configure SQL Server Compact Edition.

Opening a database

After installing the SQL Server Compact Edition developer tools CAB file you should be able to find a new Query Analyzer application within the start menu of your Windows Mobile device.

The initial window that appears after this application is started should show a series of tabs with the one labelled “Objects” selected. This tab is similiar to the Object Explorer of SQL Server 2005 Management Studio on the desktop and shows each database you have connected to in the past and the database objects contained within them.

Screenshot showing main screen of Query Analyzer application

To open a connection to an existing database you need to click the toolbar button at the bottom of the screen. This will display the following “Connect to SQL Server Compact Edition Database” dialog.

Screenshot showing Connect To Sql Server Compact Edition dialog

You need to enter the full path to your database (i.e. \Program Files\MyApplication\test.sdf) and a password if the database is password protected. Selecting the [...] button will display a file open dialog that allows you to graphically select a database file. This dialog unfortunately is restricted to database files located within the My Documents folder structure. If your database is not located within this hierarchy you will have to manually type it in.

Once the database connection details have been entered you can select the Connect button. This will return the user to the main Query Analyzer window with the specified database added to the tree view.

When you have completed your tasks with the database you should select the database within the treeview and select the toolbar button to disconnect from the database. If you do not do this it may not be possible for other applications to access the database due to Query Analyzer having a lock on the database file.

Creating a database

A new database can also be created directly on the PDA. To do this you follow the same process to open an existing database. However when the Connect to SQL Server Compact Edition database dialog appears you select the “New Database” button which will expand the connection window to include a couple of additional fields.

Screenshot showing Connect To Sql Server Compact Edition dialog after Create Database button has been pressed

The details you can enter via this dialog include:

  • Path – The full path to where the *.sdf database file should be created.
  • Password – An optional password that must be provided whenever an attempt is made to connect to the new database.
  • Sort – The sort order applied to indexes on tables within the database.
  • Encrypt – If encryption is enabled data within the database file will be encrypted. Enabling this feature will make a password mandatory since the password is the key used to decrypt the database.

After the new database has been configured clicking the Create button will return the user to the main Query Analyzer window with the newly created database added to the treeview.

Creating Tables

Screenshot showing main window of Query Analyzer after database has been created (or opened)

There are two ways to create a table within Query Analyzer. The first is to select the toolbar button while the Tables node of a database is selected. This will bring up the following Table Definition dialog that enables the user to specify a table name and define the columns within the table. These dialogs in particular are difficult to utilise on devices with small square screens.

Screenshot showing Table Definition dialog used to create a new database table graphically

An alternative to the GUI dialogs is to switch to the SQL tab of the main Query Analyzer window and enter a T-SQL data definition language (DDL) statement to create the table programatically, as shown in the screenshot below:

Screenshot showing creating a table via TSQL query execution

Once you have entered the CREATE TABLE statement you can select the toolbar button to execute the query. Query Analyzer will automatically switch to the Notes tab and inform you of the duration and outcome of the operation.

Visual Studio Tip: Three ways to use C# within a VB.NET project

Monday, March 10th, 2008

The .NET framework supports a wide range of languages meaning it is not uncommon to find code examples in a language that you are not familiar or comfortable with. This blog entry discusses some approaches that can be used to include portions of code written in a foreign language within your own application. We will demonstrate the technique by utilising C# code within a VB.NET project.

Technique 1: Code Translation

If you only have a couple of lines of C# to include within your VB.NET application you may like to attempt to manually convert the code into VB.NET so that it can be incorporated directly. If you are having difficulty converting the code (or do not have enough time to learn the specifics of another language) you could try an online code translation service such as the Developer Fusion C# to VB.NET code conversion tool which will attempt to automatically translate the code for you.

For example, given the following C# code:

public event EventHandler Foo;
 
public void FireFoo()
{
  EventHandler eh = Foo;
  if (eh != null)
    eh(this, EventArgs.Empty);
}

Developer Fusions’ code translation tool will automatically provide the following VB.NET conversion:

Public Event Foo As EventHandler 
 
Public Sub FireFoo() 
    Dim eh As EventHandler = Foo 
    RaiseEvent eh(Me, EventArgs.Empty) 
End Sub

Notice how the code translator is reasonably intelligent, for example it has removed the if statement from the original C# code snippet in favour of the VB.NET specific RaiseEvent statement which internally performs the same check. As with any automated translation utility, your milage may vary with respect to how well the translator copes with your particular code snippet.

Although this technique is useful for small amounts of code it does not lend itself well to converting large amounts of source code, or source code that utilises specialised features of a given language. For this we may like to investigate an alternative technique.

Technique 2: Class Library

Screenshot showing Solution Explorer for a solution containing both C# and VB.NET projectsOne of the many specifications surrounding the .NET environment is one called the Common Language Specification (CLS). This is a subset of CLR features that any language targeting the .NET runtime should support in order to be fully interoperable with other CLS-compliant languages. In other words if you stick to using CLS compliant language features your code should be usable in projects written in a wide range of other languages that also support the Common Language Specification. C# and VB.NET both support the Common Language Specification making it easy for these two languages to interoperate.

If you have a large amount of C# code (such as an entire class) that you would like to include within a VB.NET project you can create a C# class library project and include the source files within it. This allows you to compile the C# source code unmodified and without needing to fully understand how it works. After compilation all you have to do is add a reference to the class library from your VB.NET application as shown in the screenshot to the right. You will then be able to access the C# classes using standard VB.NET syntax.

While writing code how do you know if you are using the subset of language features that are CLS compliant? The easiest way is to add the CLSCompliant attribute to your assembly. If set to true, this will cause the C# or VB.NET compilers to emit warnings whenever they detect that you have used a language feature (or datatype etc) that is non CLS compliant.

For example within a C# class library you might add the following line to the AssemblyInfo.cs file:

using System
[assembly: CLSCompliant(true)]

Technique 3: Netmodules and assembly linking

I find as a .NET developer it is important to understand the limitations and artificial restrictions imposed by the tools I utilise. You may be surprised to know that Visual Studio does not provide access to every feature of the .NET platform.

One feature not supported by Visual Studio is the ability to compile assemblies that consist of code written in more than one language. For example having an assembly where one class is written in C# while another is written in VB.NET (or even MSIL etc).

If you are willing to drop down to command line compilation it is possible to achieve this. For example given two source files foo.cs and bar.vb we can create an assembly called myassembly.dll by executing the following commands from a Visual Studio command prompt window.

SET NETCF_DIR="C:\progra~1\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE"
 
csc /noconfig /nostdlib /r:"%NETCF_DIR%\mscorlib.dll" /t:module foo.cs
vbc /netcf /noconfig /nostdlib /sdkpath:%NETCF_DIR% /t:module bar.vb
 
link /LTCG /verbose /dll /out:myassembly.dll foo.netmodule bar.netmodule /subsystem:windows

The calls to the C# (csc) and VB.NET (vbc) command line compilers specify the /t:module parameter which causes the compiler to produce a netmodule (foo.netmodule and bar.netmodule respectively). A netmodule can be thought of as being similar to an object (*.obj) file that a native C or C++ developer may be familiar with.

Using the linker (link.exe) enables one or more netmodules to be merged into an assembly, in this case a DLL named myassembly.dll. The linker is not concerned with what language the individual netmodules were compiled from.

Sample Application

[Download multilanguageprojects.zip - 16KB]

The first sample application demonstrates creating a C# class library that can be consumed by a VB.NET winforms application. It takes the textbox cursor location code snippet I wrote in C# and turns it into a C# class library called CSharpClassLibrary.dll. This DLL is then added as a reference to the VB.NET application which makes use of the functionality to highlight the current cursor location within a multiline textbox. Only a minimal amount of C# knowledge was required to make this happen, just enough to wrap the code snippet up into a public class.

This application also demonstrates accessing functionality from an assembly which has classes written in more than one language. Within the MultiLanguageClassLibrary subdirectory you will file a small batch file that demonstrates using the command line compilers to build an assembly that contains individual classes written in C# and VB.NET. As you will see from the VB.NET sample application’s menu item there is no difficulty accessing the functionality of these classes once a reference to the assembly has been added.

[Download gps.zip - 23KB]

This blog entry was spawned by a request for a GPS Intermediate Driver example in VB.NET. The Windows Mobile 5.0 SDK includes an example of how to use this API, but it is written in C#. I have re-coded the GUI part of the GPS Intermediate Driver example into VB.NET and hence produced another example of a C# class library being used from VB.NET. This sample can be downloaded from the link above.

Improvements to the OpenFileDialog class

Saturday, March 8th, 2008

Screenshot of OpenFileDialogEx class running on a Windows Mobile Professional deviceJosé Gallardo Salazar has blogged about an enhanced OpenFileDialog implementation that fixes a number of common complaints with the standard .NET Compact Framework version. The most common complaints being not able to browse outside the “My Documents” folder and the lack of support for Smartphone (Windows Mobile Standard) devices.

As indicated in his blog entry on adding Smartphone support the OpenFileDialogEx class is still a work in progress with many possible areas of improvement. I have taken José’s source code and made a number of changes.

My improvements include:

  • Shell Icon List support – The dialog now uses the same icons as shown in File Explorer. Directories for example may have a custom icon (for example the Games folder shown in the screenshot above).
  • DPI / Resolution awareness – icons change size to match current system settings (i.e. larger icons on higher resolution devices).
  • Support for both Pocket PC and Smartphone – the platform is detected at runtime so a single assembly can alter it’s UI behaviour to run on both platforms. Some UI elements are hidden while running on a Smartphone for example.
  • Back Key support – The Back key on Smartphone Devices now moves up one directory when pressed (just like the builtin File Explorer application on WM6 devices).
  • Sorted Directory Listings – Directory entries are now sorted into alphabetical order. There is provision for the sort order to be easily modified (although this is not yet publicly exposed).
  • InitialDirectory property – This property enables the dialog to default to displaying a directory other than the root of the filesystem.

Sample Application

[Download iconviewer.zip - 22KB]

The sample application available for download demonstrates how to use the OpenFileDialogEx class and demonstrates its cross platform capability. Once you have built the application you should be able to run it on practically any Windows Mobile device and see a file dialog that is tailored to the capabilities of the current device.

One small disadvantage of my changes is the fact that the control is now less “pure”. It relies upon a number of Platform Invoke calls to access some of the system functionality not exposed by the .NET Compact Framework. An interesting note is that .NET Compact Framework version 3.5 removes the need for most of the Platform Invoke code due to new functionality or bug fixes. At this point in time however supporting .NET CF 2.0 is still important to me.

Visual Studio Tip: Discovering the Remote Tools

Thursday, March 6th, 2008

Screenshot showing path to Visual Studio Remote Tools within the Windows Start Menu

“Old” Embedded Visual C (EVC) developers will be familiar with a set of Remote Tools that enable developers to perform various tasks on a connected Windows Mobile device from the comfort of their desktop PC.

The good news is that these tools have made their way into Visual Studio 2005 and 2008. However it appears that they are less discoverable in their new home, based upon the number of forum requests where people seem to be unaware of their existence.

Instead of being located within a Tools menu within the IDE itself, the Remote Tools are now available via your Windows Start Menu, in a “Visual Studio Remote Tools” submenu. Within this menu you should find shortcuts to the following 6 tools:

  • Remote File Viewer – View and manage the file system on a target device (including exporting and importing files).
  • Remote Heap Walker – Display information about heap identifiers and flags for each process running on a target device.
  • Remote Process Viewer – Display information about each process (application) running on a target device
  • Remote Registry Editor – Display and edit the registry for a target device. Including the ability to import and export *.reg files.
  • Remote Spy – Display messages received by windows associated with applications running on a target device
  • Remote Zoom-in – Capture a screen shot from a target device and copy to the clipboard or save to disk.

These tools can come in handy while developing and debugging your smart device applications. If you use these tools regularly and hanker for them to be in the Tools menu of the Visual Studio IDE you can manually configure this by following the instructions listed on the Visual Studio for Devices team blog.

Raffael’s new blog – tips for Windows Mobile ISVs from a Microsoft Support Engineer

Tuesday, March 4th, 2008

Windows Mobile logoToday I discovered Raffael’s new blog. Raffael is a Support Engineer for Microsoft CSS (Customer Service and Support) who works to support third party developers working on the Windows Mobile platform.

Raffael has only recently started blogging by the looks of things, but already has delivered some really unique and useful insights for software developers. Not only have the posts contained technical details and code samples, they have also covered some of the “soft” and non technical aspects of software development.

For example I particularly liked the article about “Supporting Kiosk-mode applications on Windows Mobile” which discusses the difference between something being “technically achievable” and “supported”. This touches on the notion that just because something is feasibly possible it doesn’t mean it’s the correct thing to be doing.

Another interesting post was one discussing device driver development and the “support boundaries” for different types of developers.

This is definitely a blog that is worth keeping an eye on if you develop for the Windows Mobile platform, it promises lots of interesting tips and insights into Windows Mobile development. The only thing I would suggest is missing from the blog at the moment is a short bio, or welcome post. I’m not sure of Raffael’s last name for instance, and couldn’t find it via the blog.