• 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());
        }

  • 相关阅读:
    微软发布全球建筑物数据
    echarts 迁徙地图的实现
    React剖析之组件基础
    React剖析之状态管理
    日常小记微信小程序
    SpringCloud中集成OenFeign时设置请求服务超时时间
    SpringCloud中集成Hystrix后通过Dashboard实现图形化监控实现
    SpringCloud中集成Hystrix实现熔断(从实例入手)
    SpringCloud中集成Hystrix实现降级时通过FeignFallBack实现通配服务
    SpringCloud中集成OpenFeign实现服务调用
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/2620977.html
Copyright © 2020-2023  润新知