zoukankan      html  css  js  c++  java
  • How to: Get the Device Platform(转)

    http://msdn.microsoft.com/en-us/library/ms229660.aspx
     1 public class PlatformDetector
     2 {
     3     [DllImport("coredll.dll")]
     4     private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
     5 
     6     private static uint SPI_GETPLATFORMTYPE = 257;
     7 
     8     public static Platform GetPlatform()
     9     {
    10         Platform plat = Platform.Unknown;
    11         switch (System.Environment.OSVersion.Platform)
    12         {
    13             case PlatformID.Win32NT:
    14                 plat = Platform.Win32NT;
    15                 break;
    16             case PlatformID.Win32S:
    17                 plat = Platform.Win32S;
    18                 break;
    19             case PlatformID.Win32Windows:
    20                 plat = Platform.Win32Windows;
    21                 break;
    22             case PlatformID.WinCE:
    23                 plat = CheckWinCEPlatform();
    24                 break;
    25         }
    26 
    27         return plat;
    28     }
    29 
    30     static Platform CheckWinCEPlatform()
    31     {
    32         Platform plat = Platform.WindowsCE;
    33         StringBuilder strbuild = new StringBuilder(200);
    34         SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0);
    35         string str = strbuild.ToString();
    36         switch (str)
    37         {
    38             case "PocketPC":
    39                 plat = Platform.PocketPC;
    40                 break;
    41             case "SmartPhone":
    42                 // Note that the strbuild parameter from the
    43                 // PInvoke returns "SmartPhone" with an
    44                 // upper case P. The correct casing is
    45                 // "Smartphone" with a lower case p.
    46                 plat = Platform.Smartphone;
    47                 break;
    48         }
    49         return plat;
    50     }
    51 }
    52 
    53 public enum Platform
    54 {
    55     PocketPC, WindowsCE, Smartphone, Win32NT, Win32S, Win32Windows, Unknown

    56 } 

    [DllImport("coredll.dll", SetLastError = true)]
    private static extern bool KernelIoControl(Int32 dwIoControlCode,
        IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf,
        Int32 nOutBufSize, ref Int32 lpBytesReturned);

    private void DeviceType_Load(object sender, System.EventArgs e)
    {
        try
        {

            MessageBox.Show("Platform is " + PlatformDetector.GetPlatform());
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }

  • 相关阅读:
    Qt C++中的关键字explicit——防止隐式转换(也就是Java里的装箱),必须写清楚
    有栖川有栖《马来铁道之谜》读后感
    Qt多国语言QT_TR_NOOP和QT_TRANSLATE_NOOP
    Qt调用VC++生成的动态链接库
    QTabWidget添加自定义样式
    Qt跨线程信号和槽的连接(默认方式是直连和队列的折中)
    OO五大原则
    《Head First Python》学习笔记03 异常处理
    使用Qt实现MDI风格的主窗体
    Qt中文乱码问题(比较清楚,同一个二进制串被解释成不同的语言)
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/2620977.html
Copyright © 2011-2022 走看看