Registering file extensions with Windows Mobile apps

I took a break from playing with the Android SDK for the first time tonight by making a quick update to my Windows Mobile notepad app.

Previously, to open files I’ve had to launch the notepad, then use File -> Open and choose my file. I wanted to register the .txt file extension with the notepad app, so that I can open files in the notepad by clicking on them. It’s a fairly straightforward thing to do, but I thought it might be helpful to share.

I couldn’t find much information about it, but it’s fairly simple to work out if you use Visual Studio’s Remote Registry Editor to see how other apps do it.

In short, you have to get your CAB installer file to write some entries to the HKEY_CLASSES_ROOT subtree of the registry. There are two bits: the first is a key that identifies the file extension in question and associates it with the second – a key that describes it, and how to open it.

I’m assuming you already know how to create an installer CAB file and that you’re using Visual Studio 2005 (or something similar). Here is how you add the ability to register a custom file extension.

Right-click on the Installer ‘Smart Device Deployment’ project in the ‘Solution Explorer’, and click on ‘View’ -> ‘Registry’.

Right-click on HKEY_CLASSES_ROOT, and add a new key. Rename the new key to .xxx (where xxx is your new file extension)

Right-click on the new .xxx key, and add a new string value. Delete the string value’s name (so that is named (Default)). Set the value to xxxfile

Right-click on HKEY_CLASSES_ROOT, and add a new key. Rename the new key to xxxfile

Keep adding new keys to build the following subtree:

+--- xxxfile
       +--- Shell
              +--- Open
              |       |
              |       +--- Command
              +--- OpenDoc
                      +--- Command              

Add new (Default) string values to the two ‘Command’ keys.

For HKCR\xxxfile\Shell\Open\Command set the string value to
""%InstallDir%\YourApp.exe"" ""%%1""
(including all the double-quotes)

For HKCR\xxxfile\Shell\OpenDoc\Command set the string value to
""%InstallDir%\YourApp.exe"" -opendoc ""%%1""
(including all the double-quotes)

That’s it. 🙂

Tags: , , , , , , , ,

6 Responses to “Registering file extensions with Windows Mobile apps”

  1. putrasto says:

    thanks you for the tip. Very helpful 🙂
    btw, is it possible to change the icon, in my case the explorer still display the default icon (i want to change to something else).

  2. dale says:

    @putrasto – Glad you find it useful!

    I’ve not tried changing the icon. I imagine it’s another registry entry to point to an exe with the icon, but I’d have to experiment.

    If you have Visual Studio, one of the tools with that is a Remote Registry Editor – you could always point that at your phone (or an emulator) and examine the existing file extensions. If you look at the registry key for something like .doc files, it’d probably be straightforward to copy the approach.

  3. ffonz says:

    The icon is done with:
    +— xxxfile
    +— DefaultIcon
    For HKCR\xxxfile\DefaultIcon set the string value to
    “”%InstallDir%\YourApp.exe”, 0″
    (including all the double-quotes)

  4. ffonz says:

    Sorry, forgot to mention the ‘0’ is for .Net applications. For C++ applications the resourceID has to be used, preceded with a minus sign, I believe.
    And don’t mention the lines in the tree in my previous comment. Preceding spaces have be removed. 🙁

  5. dale says:

    ffonz – Thanks very much for that – very useful.

  6. Fahim Israque Ahmad says:

    If you want to change icon use the software sk shortcut manager 1.1.1. Btw thanx for the helpful regediting post.