Platform detection II: Is your app running on Smartphone or Pocket PC?
While both Smartphones and Pocket PCs are based on Windows Mobile, there are some very important differences for developers who are targeting both platforms. Not the least of which are lack of LinkButtons and other clickable elements on Smartphones (since they have no touch screen). In this post I show how to detect whether your app is running on a Smartphone or a Pocket PC style Windows Mobile device.
It is a simple call to SystemParametersInfo to find whether you are running on a Smartphone or a Pocket PC. You need a few constants defined and the P/Invoke marshaling code to make it work from managed code however.
This post builds on the first post in the Platform Detection series. You'll need to build on the code from that post for this post to compile and run. Like the last post, this code uses partial classes, so you can copy and paste the previous post's code into one file and this code into another (removing the first post's Main method) and your project will compile and run.
using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Text;
namespace PlatformDetection
{
internal partial class PInvoke
{
public static string GetPlatformType()
{
StringBuilder platformType = new StringBuilder(50);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETPLATFORMTYPE,
(uint)platformType.Capacity, platformType, 0) == 0)
throw new Exception("Error getting platform type.");
return platformType.ToString();
}
}
internal partial class PlatformDetection
{
public static bool IsSmartphone()
{
return PInvoke.GetPlatformType() == "SmartPhone";
}
public static bool IsPocketPC()
{
return PInvoke.GetPlatformType() == "PocketPC";
}
}
class PlatformProgram
{
static void Main(string[] args)
{
string platform;
if (PlatformDetection.IsSmartphone())
platform = "Smartphone";
else if (PlatformDetection.IsPocketPC())
platform = "Pocket PC";
else
platform = "Other WinCE";
MessageBox.Show("Platform: " + platform);
}
}
}
This is the second post in a series of three on platform detection. Coming up next: detecting the presence of a touch screen.
Comments
Anonymous
September 22, 2006
When you develop your Windows CE or Windows Mobile application in .NET Compact Framework, you probably do a lot of testing on the Microsoft Device Emulators for Smartphone and Pocket PC. Here I describe how to detect whether your program is running onAnonymous
March 16, 2007
是否曾经想过要设计一个.NETCF应用程序,它能够同时在PocketPC和Smartphone平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在Pock...Anonymous
June 15, 2007
I now have three blogs that I post to: this one, JMPInline , and NetCFTeam . Which posts will I put where?Anonymous
June 15, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/06/15/identity-crisis/Anonymous
June 21, 2007
是否曾经想过要设计一个 .NET CF 应用程序,它能够同时在 Pocket PC 和 Smartphone 平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在 Pocket PC 上还是 Smartphone上,甚至是模拟器上呢?Anonymous
February 08, 2008
本文介绍了如何利用.NET CF3.5的新功能方便的确定设备类型Smartphone,PPC or PPC Phone?Anonymous
January 21, 2009
PingBack from http://www.keyongtech.com/467416-accessing-system-information-os-deviceAnonymous
May 09, 2009
作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。Anonymous
May 09, 2009
作者:马宁在开发WindowsCE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在PocketPC、Smartphone还是WindowsCE上。在这篇文章里,我们介绍如何编写一个...Anonymous
May 09, 2009
作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。Anonymous
May 09, 2009
PingBack from http://microsoft-sharepoint.simplynetdev.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-12/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-15/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-14/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-6/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-3/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-11/Anonymous
May 09, 2009
PingBack from http://asp-net-hosting.simplynetdev.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-16/Anonymous
May 09, 2009
PingBack from http://www.anith.com/?p=36383Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-18/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-19/Anonymous
May 10, 2009
PingBack from http://tune-up-pc.com/blog/?p=1654Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-2/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-5/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-8/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-13/