Before I get to my main point (.NET CF 3.5 feature that simplifies determining the device type) I just need to take a moment and comment on the snow here in New Hampshire. I live in the NH Seacoast area, which may sound funny but NH does have a whopping 13 miles (or is it 15 miles ... hmmm) of Atlantic Ocean coastline. The Seacoast is supposed to be one of the more temperate areas of the state and for the most part it is. But this year things are different.
Now I'm not one to complain about the cold or snow - it's NH ... it's supposed to be cold & snowy. That said this year is different. We've had 4 significant snowfalls in the past two weeks; 3 of them actual snow storms with the snowfall rates reaching over 2 inches/hour. I don't know how much snow we have on the ground in total but I'm certain that it is more snow than we've ever had before Christmas in the 8 years I've lived here. This picture was taken from my (home) office window about 2 hours ago (~2:00 PM EST).
The buried fence there is about 4 feet tall. Some of the depth of the snow built-up on the fence is from the township plowing the sidewalk but most of it is the actual snowfall. I didn't get a picture of my deck but the snow on the deck has now built-up so much that it's reached the bottom of the windows - probably gonna have to dig that down this weekend - And just think ... Winter starts in just 2 days
But that's not why I'm posting...
I don't know how many people have had a chance to checkout What's New in the .NET Compact Framework Version 3.5 - there's a little section entitled Platform ID that's easy to miss but it describes a very important and long-awaited feature: the ability to determine if your application is running on Pocket PC-style device or Smartphone-style device.
Finally we no longer have to P/Invoke out to the SystemParametersInfo native function passing integer constants and StringBuilder instances; it's now just a simple property check: SystemSettings.Platform
if (SystemSettings.Platform == WinCEPlatform.PocketPC)
txtDeviceType.Text = "Windows Mobile Professional";
else if (SystemSettings.Platform == WinCEPlatform.Smartphone)
txtDeviceType.Text = "Windows Mobile Standard";
else
txtDeviceType.Text = "Not Windows Mobile";
Note (21-Dec-2007) - A more complete version of this code snippet is available here.
With this, we can finally check the platform type as easily as we've been able to check the operating system version and CLR version since .NET CF 1.0. To access the SystemSettings class and WinCEPlatform enumeration you'll need to add a reference to the Microsoft.WindowsCE.Forms assembly and provide the necessary using/import for the corresponding namespace.
If you need to make the platform determination in a pre .NET CF 3.5 environment, or if you just like telling stories about how hard things were "back in your day", the How Do I: Detect and Identify a Mobile Device? video provides a complete walkthrough of how to use the SystemParametersInfo native function.
I've been meaning to blog about this for a while (SystemSettings.Platform not snow J) - ah, finally
Posted
Dec 20 2007, 02:56 PM
by
jim-wilson