# Monday, February 26, 2007

Programmatically Activating Speakerphone

Windows Mobile devices, both Smartphone and Pocket PC support Speakerphone functionality. When operating through the Phone application the end user can toggle the state, up until now there has been no documented way to achieve this through code. Last year I investigated the issue on behalf of one of my readers and failed on several attempts at simulating a press-and-hold of the green phone button. It turns out that the device issues a specific key constant to change the state, and this can be simulated through code. It also turns out that the constant is equivalent to VK_F16 (thats Keys.F16 for managed code). I've wrapped up the necessary P/Invoke into the following code:-

public sealed class SpeakerPhone
{
private SpeakerPhone() { }

/// <summary>
/// Toggles the SpeakerPhone state.
/// </summary>
public static void Toggle()
{
//keydown
NativeMethods.keybd_event((byte)Keys.F16, 0, 0, 0);
//keyup
NativeMethods.keybd_event((byte)Keys.F16, 0, NativeMethods.KEYEVENTF_KEYUP, 0);
}

internal static class NativeMethods
{
internal const int KEYEVENTF_KEYUP = 0x0002;


[System.Runtime.InteropServices.DllImport("coredll.dll")]
internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
}
}

 

Since this just toggles the state, you can't determine the current state at any particular time. This code has been tested on Windows Mobile 5.0 and beyond (It possibly works on Windows Mobile 2003 but I haven't tested), it doesn't work on the Windows Mobile 5.0 Emulators as Speakerphone isn't implemented. I was able to establish a call on speakerphone using the following code:

Microsoft.WindowsMobile.Telephony.Phone p = new Microsoft.WindowsMobile.Telephony.Phone();
p.Talk("01234567890");
SpeakerPhone.Toggle();

Once the call is ended the speakerphone state is restored on subsequent calls.

#    |
# Wednesday, February 21, 2007

Richard Jones is Blogging

Richard has just started blogging, starting with a sample for maximising screen space by creating a Vista style textbox with integral label, and a description of what he has been up to in the fight against "Monkey Code". I've subscribed to his RSS feed and added him to the blogroll.

#    |
# Saturday, February 17, 2007

Emulator Images in the Windows Mobile 6 SDKs

The Windows Mobile 5.0 SDKs shipped with a number of emulator images, and additional form factors were made available in separate packages at a later date when they were introduced with AKU2. Below is the list of emulator images which will ship with the Windows Mobile 6 SDK:-

Windows Mobile 6 Standard

  • Windows Mobile 6 Standard (176x220)
  • Windows Mobile 6 Standard Landscape QVGA (320x240)
  • Windows Mobile 6 Standard QVGA (240x320)

Windows Mobile 6 Professional

  • Windows Mobile 6 Classic (No Phone) (240x320)
  • Windows Mobile 6 Professional (240x320)
  • Windows Mobile 6 Professional Square (240x240)
  • Windows Mobile 6 Professional Square QVGA (320x320)
  • Windows Mobile 6 Professional Square VGA (480x480)
  • Windows Mobile 6 Professional VGA (480x640)

Except for the square form-factors all of the Professional emulator images support screen rotation, the emulator rotates the device skin in place so that the screen is always shown in the correct orientation on the development computer.

#    |
# Thursday, February 15, 2007

Windows Mobile 6 SDKs Update

Turns out the SDKs haven't been abducted by aliens, James Pratt reveals the story here on the Windows Mobile blog. So if you missed them you'll have to wait until 1st March for their official release.

The good news is that there will be an update to the SDKs due out on May 1st with new emulator images, additional samples and documentation improvements. Lets hope that all my bug reports submitted on documentation errors in the current release are resolved in that release.

#    |
# Wednesday, February 14, 2007

What's New For Managed Developers In Windows Mobile 6 (Part 2)

When I previously posted the list of additional system properties I was using the Windows Mobile 6 SDK Documentation as a reference. Well it turns out that there are even more new properties, you can view them using Object Browser in your project but they aren't included in the documentation. The other new properties are:-

  • CameraEnabled - This in addition to existing CameraPresent property
  • CellularSystemAvailable1xrtt
  • CellularSystemAvailableEdge
  • CellularSystemAvailableEvdo
  • CellularSystemAvailableEvdv
  • CellularSystemAvailableGprs
  • CellularSystemAvailableHsdpa
  • CellularSystemAvailableUmts
  • CellularSystemConnected1xrtt
  • CellularSystemConnectedEdge
  • CellularSystemConnectedEvdo
  • CellularSystemConnectedEvdv
  • CellularSystemConnectedGprs
  • CellularSystemConnectedHsdpa
  • CellularSystemConnectedUmts
  • ClamshellClosed
  • DeviceLocked
  • KeyLocked
  • LockStates - A combination of flags for Device, Key and Sim locks
  • SimLocked
  • PhoneTalkingCallStartTime

 

#    |
# Monday, February 12, 2007

32feet.NET v2.1 Released

Yesterday I released the latest update to the personal area networking library to the 32feet.NET site. This release focussed on bug fixes and improved compatibility and error handling. This release supports device discovery on the latest WM5.0 AKU3 devices and beyond where the registry layout has undergone a few undocumented changes. You can view the full list of closed work items for this release on the CodePlex workspace.

The code also now has unit testing (not yet covering all functionality) and a new sample application for using IrDA on desktop Windows versions.

#    |
# Saturday, February 10, 2007

What's New For Managed Developers In Windows Mobile 6

At first glance it doesn't appear there are any new goodies in the managed code libraries for Windows Mobile 6. But wait, there are - SystemState has gained a few new properties which allow you to monitor the state of:-

  • BluetoothStateA2DPConnected
  • BluetoothStateDiscoverable
  • BluetoothStateHandsFreeAudio
  • BluetoothStateHandsFreeControl
  • BluetoothStateHardwarePresent
  • BluetoothStatePowerOn

and

  • WiFiStateConnected
  • WiFiStateConnecting
  • WiFiStateHardwarePresent
  • WiFiStateNetworksAvailable
  • WiFiStatePowerOn

Another noticable enhancement, which isn't really part of the managed APIs, is that the dialog for Task items (Task.ShowDialog()) is now much more useful on Smartphone (sorry Standard Edition) in that it has an Edit option with the ability to set properties such as Priority, Status, Reminder etc. These have always been present in Pocket PC (oops Professional Edition) and sorely lacking from Smartphone prior to WM6.

#    |

Am I Running on Windows Mobile 6

Following Daniel's post announcing the appearance of the Windows Mobile 6 SDKs on Microsoft's download site, I headed off to get the SDKs and start poking around. A common question I can see arising is how to detect if you are running on WM6 from your managed code. The answer is to use the System.Environment.OSVersion.Version property. If your device is running WM6 this will report back 5.2 (for the emulators the full build is 5.2.318 but the build numbers are likely to change by the time real devices emerge). In contrast WM5.0 devices report back 5.1 (5.1.1700 for the original 5.0 SDK emulators). Both platforms are running on top of Windows CE 5.0, and not Windows Embedded CE 6.0 which is currently available, and understandably this can cause some confusion when the OS and marketing versions don't exactly tie up. The .1 and .2 minor versions are special Windows CE releases for Windows Mobile which are not available to generic CE platform builders. You may remember a similar thing occuring with Windows Mobile 2003 Second Edition which had an OS version of 4.21.

#    |
# Thursday, February 08, 2007

Windows Mobile 6 for Developers

You've probably not managed to miss the barrage of reports announcing the upcoming Windows Mobile 6. One in particular caught my eye which was by Loke Uei on new developer features:-

http://blogs.msdn.com/lokeuei/archive/2007/02/07/windows-mobile-6-what-s-in-it-for-developers.aspx

On the device the main highlights are the latest framework and SQL Server CE components in ROM, and two new APIs:-

  • Windows Ink Services Platform (WISP) Lite
  • New Sound API - Plays MP3s and more

    The first came as a bit of a shock, after all in Windows Mobile 5.0 the number of places in the OS where Ink was used was reduced, no more Ink notes on Pocket Outlook items for example. I'll be interested to see what this API supports.

    The sound functionality will be greeted with cheers by many developers, there are many occasions when you need to simply play a wma or mp3 audio file and there isn't anything as comfortable to use as PlaySound and yet supporting audio types other than .wav.

    There are a number of improvements to the Emulator tools which are always welcome, especially in the early stages when it will be difficult to get hold of Windows Mobile 6 devices. The last item on the list entitled "Platform unification investments" is rather vague, I look forward to finding out exactly what this means for the end developer. Anything that simplifies writing code once for the multitude of Windows Mobile versions and form factors available gets my full approval!

  • #    |
    # Thursday, February 01, 2007

    Windows Mobile Device Center Released

    A couple of days after Vista's official release we now have the final version of Windows Mobile Device Center. This news comes hot off the press from Josh at Windows Connected. If you are running the Beta release grab yourself the final version here:-

    http://www.microsoft.com/downloads/details.aspx?FamilyID=83d513ea-9df9-4920-af33-3a0e2e4e7beb&DisplayLang=en

    #    |
    # Wednesday, January 17, 2007

    Bluetooth RSSI

    By chance I was looking through the Windows CE 6.0 documentation and cam across a new Bluetooth method - BthReadRSSI. My interest was heightened when reading the Requirements section. Apparently the method is supported on Windows Mobile 5.0 as well as CE 6.0. Without further ado I added the P/Invoke definition to the 32feet source and did some quick tests on my iMate JasJar. The method was present, however it returned the error code 0x00000490 which according to the error lookup tool represents "Element not found". So thats where I leave it for now, but I'd be interested to hear from you if you have another device or a Bluetooth equipped CE 6.0 device. You can download the latest 32feet source from the CodePlex project which has this functionality - see the BluetoothDeviceInfo.Rssi property.

    #    |
    # Wednesday, January 10, 2007

    SQL Server Compact Edition - Coming Tomorrow

    Excellent news from the SQL Server Everywhere blog (those guys need to change the name of their blog again :-)). Tomorrow the runtimes and tools for SQL Server Compact Edition will be released to the web. It will replace the RC1 download so the link will remain the same:-

    http://www.microsoft.com/downloads/details.aspx?FamilyID=85E0C3CE-3FA1-453A-8CE9-AF6CA20946C3&displaylang=en

     

    #    |
    # Saturday, December 30, 2006

    5 Things

    Daniel tagged me a couple of days ago and finally I've got round to posting. I've been enjoying some quality offline time over the Christmas break.

    1. I'm in the process of writing a .NET book with Daniel and fellow MVP Andy.
    2. I'm double jointed and can put my legs behind my head, but I'm getting a little rusty in my old age.
    3. While trying to buy a practical car I was let down twice by a dealership, so I went elsewhere and got myself a much more impractical 2 seat convertible and have thoroughly enjoyed it.
    4. Before studying Computer Science I briefly entered the world of bricks and mortar training as an architect.
    5. I enjoy travelling to new places, this year I spent a month in Australia, somewhere I'd definitely like to revisit.

    And finally to tag 5 new victims bloggers - Bill, Dave, Rob, João Paulo and John

    #    |
    # Tuesday, December 12, 2006

    Pastie McCode

    Is Pastie McCode the next Barry Scott? Well probably not, but if you are a UK business who is interested in getting up to speed with Vista and Office 2007 then you may want to find out more.

    http://ukvistaofficelaunchtour.spaces.live.com/

    #    |
    # Thursday, November 30, 2006

    Make Individual TreeView Nodes Bold

    The full framework TreeView control supports setting a Font on a per-node basis, the Compact Framework control doesn't support this, however with a little interop magic you can mark individual nodes as Bold. Because the .NETCF v2.0 TreeView control exposes it's own window handle, and each TreeNode also exposes it's handle, we have all the raw data we need to format the node. First we need to define a structure and a couple of enumerations:-

    internal struct TVITEM
    {
    public TVIF mask;
    public IntPtr hItem;
    public TVIS state;
    public TVIS stateMask;
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
    string pszText;
    int cchTextMax;
    int iImage;
    int iSelectedImage;
    int cChildren;
    int lParam;
    }

    [Flags()]
    internal enum TVIF
    {
    TEXT =0x0001,
    IMAGE =0x0002,
    PARAM =0x0004,
    STATE =0x0008,
    HANDLE =0x0010,
    SELECTEDIMAGE =0x0020,
    CHILDREN =0x0040,
    }

    [Flags()]
    internal enum TVIS
    {
    SELECTED =0x0002,
    CUT =0x0004,
    DROPHILITED =0x0008,
    BOLD =0x0010,
    EXPANDED =0x0020,
    EXPANDEDONCE =0x0040,
    EXPANDPARTIAL =0x0080,

    OVERLAYMASK =0x0F00,
    STATEIMAGEMASK =0xF000,
    USERMASK =0xF000,
    }

     

    Then I've created a single static method which can set the bold state of any node:-

    public static void SetNodeEmphasis(TreeNode n, bool bold)
    {
    //get the control and node handles
    IntPtr hTreeview = n.TreeView.Handle;
    IntPtr hNode = n.Handle;

    //create a TVITEM struct
    TVITEM t = new TVITEM();
    t.hItem = hNode;
    //mark only the handle and state members as valid
    t.mask = TVIF.HANDLE | TVIF.STATE;
    //set the state to bold if bold param was true
    t.state = bold ? TVIS.BOLD : 0;
    //set statemask to show we want to set the bold state
    t.stateMask = TVIS.BOLD;

    //pin the struct in memory
    GCHandle hTVITEM = GCHandle.Alloc(t, GCHandleType.Pinned);
    //create a TVM_SETITEM message with the handle of our pinned struct
    Microsoft.WindowsCE.Forms.Message m = Microsoft.WindowsCE.Forms.Message.Create(hTreeview, 0x113F, IntPtr.Zero, hTVITEM.AddrOfPinnedObject());
    //send the message to the treeview
    Microsoft.WindowsCE.Forms.MessageWindow.SendMessage(ref m);
    //free the pinned structure
    hTVITEM.Free();
    }

    The method is easy to reuse as you only need to pass the TreeNode in, it will grab the handle of the parent control from the node itself. After applying the formatting to a couple of nodes you'll get something like this:-

     

    #    |