请教大家,程序中如何判定是在平台是2003还是在5。0

xw1980xw 2007-01-08 08:05:58
同上!
...全文
210 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
huluoboo 2007-01-18
  • 打赏
  • 举报
回复
以下片段摘自我以前的文章,希望对你有用。

最终版本提供的检测功能:
• IsWinCE ()
• IsEmulator ()
• IsSmartPhone ()
• IsPockPC ()
• IsTouchScreen ()

源码如下:
using System;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Text;

namespace PlatformDetection
{
internal class PInvoke
{
[DllImport("Coredll.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode)]
static extern int SystemParametersInfo4Strings(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);

const int MAX_PATH = 260;
[DllImport("Coredll.dll")]
static extern int SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, int nFolder, int fCreate);

public enum SystemParametersInfoActions : uint
{
SPI_GETPLATFORMTYPE = 257, // this is used elsewhere for Smartphone/PocketPC detection
SPI_GETOEMINFO = 258,
}

public static string GetOemInfo()
{
//10/26/2006 wangyun Change from 50 to 100, as it doesn't work on "FUJITSU SIEMENS COMPUTERS Pocket LOOX"
StringBuilder oemInfo = new StringBuilder(100);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETOEMINFO,
(uint)oemInfo.Capacity, oemInfo, 0) == 0)
throw new Exception("Error getting OEM info.");
return oemInfo.ToString();
}

public static string GetPlatformType()
{
//10/26/2006 wangyun Change from 50 to 100 to avoid the possible bug as above
StringBuilder platformType = new StringBuilder(100);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETPLATFORMTYPE,
(uint)platformType.Capacity, platformType, 0) == 0)
throw new Exception("Error getting platform type.");
return platformType.ToString();
}

public enum SpecialFolders : int
{
CSIDL_WINDOWS = 0x0024,
}

public static string GetSpecialFolder(SpecialFolders specialFolder)
{
StringBuilder path = new StringBuilder(MAX_PATH);
if (SHGetSpecialFolderPath(IntPtr.Zero, path, (int)specialFolder, 0) == 0)
throw new Exception("Error getting Windows path.");
return path.ToString();
}
}

public class PlatformDetection
{
private const string MicrosoftEmulatorOemValue = "Microsoft DeviceEmulator";

//10/26/2006 wangyun To effect compatibility between PC and PDA devices
public static bool IsWinCE()
{
return System.Environment.OSVersion.Platform == PlatformID.WinCE;
}

public static bool IsEmulator()
{
if (IsWinCE())
return PInvoke.GetOemInfo() == MicrosoftEmulatorOemValue;
else
return false;
}

public static bool IsSmartphone()
{
if (IsWinCE())
return PInvoke.GetPlatformType() == "SmartPhone";
else
return false;
}

public static bool IsPocketPC()
{
if (IsWinCE())
return PInvoke.GetPlatformType() == "PocketPC";
else
return false;
}

public static bool IsTouchScreen()
{
if (IsWinCE())
{
string driverFileName = Registry.GetValue(@"HKEY_LOCAL_MACHINE\Hardware\DeviceMap\Touch",
"DriverName", "touch.dll").ToString();
string windowsFolder = PInvoke.GetSpecialFolder(PInvoke.SpecialFolders.CSIDL_WINDOWS);
string driverPath = Path.Combine(windowsFolder, driverFileName);
bool driverExists = File.Exists(driverPath);

return
driverExists &&
// Windows Mobile 5.0 Smartphone emulator and earlier has a driver, but no touch screen.
!(IsSmartphone() && IsEmulator() && Environment.OSVersion.Version.Major < 6);
}
else
return false;
}
}
}
tomcat119 2007-01-09
  • 打赏
  • 举报
回复
GetVersionEx

7,656

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧