Welcome to MSDN Blogs Sign in | Join | Help

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.

Published Friday, September 22, 2006 9:24 AM by NetCFTeam

Comments

# Platform detection I: How to detect that your app is running in the emulator

Friday, September 22, 2006 12:26 PM by .NET Compact Framework Team
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 on

# 您的 .NET CF 程序到底运行在什么平台上?

Saturday, March 17, 2007 7:45 AM by Bob Li

是否曾经想过要设计一个.NETCF应用程序,它能够同时在PocketPC和Smartphone平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在Pock...

# Identity crisis

Friday, June 15, 2007 1:54 PM by Andrew Arnott

I now have three blogs that I post to: this one, JMPInline , and NetCFTeam . Which posts will I put where?

# MSDN Blog Postings · Identity crisis

Friday, June 15, 2007 4:39 PM by MSDN Blog Postings · Identity crisis

# 您的 .NET CF 程序到底运行在什么平台上?

Thursday, June 21, 2007 7:45 PM by Bob Li

是否曾经想过要设计一个 .NET CF 应用程序,它能够同时在 Pocket PC 和 Smartphone 平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在 Pocket PC 上还是 Smartphone上,甚至是模拟器上呢?

# [CF Skills].NET CF3.5中确定设备的的平台类型

Friday, February 08, 2008 12:27 PM by fox23

本文介绍了如何利用.NET CF3.5的新功能方便的确定设备类型Smartphone,PPC or PPC Phone?

# Accessing System Information (OS, Device type, etc) | keyongtech

# 如何修改Windows CE的平台类型

Saturday, May 09, 2009 11:14 PM by 马宁的Windows Embedded研究

作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。

# 如何修改Windows CE的平台类型

Saturday, May 09, 2009 11:17 PM by 马宁

作者:马宁在开发WindowsCE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在PocketPC、Smartphone还是WindowsCE上。在这篇文章里,我们介绍如何编写一个...

# 如何修改Windows CE的平台类型

Saturday, May 09, 2009 11:18 PM by Windows Embedded CE 中国研发团队

作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。

# Anith » ????????????Windows CE???????????????

# Tune Up Your PC » Post Topic » ????????????Windows CE???????????????

Anonymous comments are disabled
 
Page view tracker