One of the new features in v3.5 of the Compact Framework is the ability to easily detect the platform you are running on from Smartphone (Standard Edition), PocketPC (Classic or Professional Editions) or WinCEGeneric (Everything else). The code is very straight-forward:-
if(SystemSettings.Platform == WinCEPlatform.Smartphone)
//do something smartphone specific…
In the latest (v3.0) version of Mobile In The Hand I’ve implemented a matching property, so for the above code sample you’d just change the using statement to use InTheHand.WindowsCE.Forms and the code would work the same way. This is available in both the .NETCF v1.0 and v2.0 builds of the library.
In The Hand Ltd today released Networking In The Hand, a developer library for the .NET Compact Framework 2.0 and 3.5 Beta. This library adds additional networking functionality not found in in the Compact Framework while matching the object model used in the full .NET framework to make it easy to share your code between platforms. Functionality includes:-
InTheHand.Net.WebClient – Provides helper methods for working with information upload and download over HTTP and FTP transports, and any other WebRequest based implementations.
InTheHand.Net.FtpWebRequest – Provides a complete desktop compatible implementation of the WebRequest pattern for FTP.
InTheHand.Net.WebRequestMethods – Provides a reference of all the HTTP and FTP methods (GET/POST etc)
InTheHand.Net.NetworkInformation.Ping – Perform a Ping and determine network availability and performance.
InTheHand.Net.NetworkInformation.IPGlobalProperties – Retrieve a wide range of networking statistics to measure traffic and help identify faults.
The library is licensed on a per-developer basis with no additional royalties required to distribute the runtime with your applications. Full details on the product can be found on the product details page – http://inthehand.com/content/Networking.aspx. A fully functionality Evaluation version is available to download – http://inthehand.com/files/folders/evals/entry4014.aspx.
In .NETCF v3.5 there is a new namespace – System.Media which brings audio support to the Compact Framework. Previously the common way to add sounds to your application was to use the PlaySound API (either P/Invoking yourself or using one of many wrappers). Now that the framework itself has built-in support, which matches the desktop .NET v2.0 framework it makes sense to standardise on the SoundPlayer component.
There are some differences in behaviour which you’ll need to be aware of. When you specify a filename this doesn’t simply call through to the native APIs passing the filename, the file is first loaded into memory and then the WaveOut APIs are used to play it. This means that if you simply create a new SoundPlayer and call Play the file will not be loaded, the Play method will have to first load the file contents, and then play the sound. This will create a noticable delay before the sound is heard. The class allows you to load the file at any time prior to calling play – you can use either Load or LoadAsync to do this. Once the file is loaded the Play method will be able to immediately begin playing the file. Exactly where you call the Load/LoadAsync method will depend on your application design. Keeping a large audio file cached will tie up valuable memory, you should dispose of the SoundPlayer instance once you have finished with it.
On the newsgroup somebody asked how to have multiple lines of text on a .NETCF Button control. The native control supports this but the appropriate style is not set by default. The following code snippet shows how to enable this:-
private const int BS_MULTILINE = 0x00002000;
private const int GWL_STYLE = -16;
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
public static void MakeButtonMultiline(Button b)
IntPtr hwnd = b.Handle;
int currentStyle = GetWindowLong(hwnd, GWL_STYLE);
int newStyle = SetWindowLong(hwnd, GWL_STYLE, currentStyle | BS_MULTILINE);
The usage is simple, just pass the specific Button control to MakeButtonMultiline:-
Here is what the amended button looks like on the left (default appearance on the right)
The designer fully supports entering multiple lines for the Button Text property, just click the dropdown at the end of the field and it will pop up a window into which you can add linebreaks with your text.
I’m now a member of the CodePlex workspace for the Facebook Developer Toolkit. I’ve been working on porting across my modifications into the codebase. The .NETCF v2.0 version uses a project called Facebook.Compact but refers to the existing source files from the desktop project. Then some conditional compilation is used to hide a few unsupported features from .NETCF and implement some workarounds for missing functionality. This will be a familiar technique if you’ve been to Daniel‘s sessions (or read his blog posts on the subject). It’s not quite working yet since my code made use of a couple of my own libraries for speed, so I’ll need to implement a few of the features within those in the Facebook.Compact project.
The Facebook API allows third-party web and desktop applications to interact with Facebook features. There is an excellent shared-source library for .NET to wrap the Facebook calls but currently it only supports the full framework. I did some work converting this source to compile and run on .NETCF v2.0. There are some example screens here of the login process, and pulling back information about our book group.
Since the login screen uses the same page as the desktop it’s not a great fit on a Pocket PC screen, so that’s an area for improvement.