Tuesday, January 12, 2016
Ask you, how the program is determined on the platform in 2003 or 5.0
Ditto!
Reply:
GetVersionEx
Reply:
The following excerpts from my previous article, I hope useful to you.
The final version provides a detection function:
& Amp; # 8226; IsWinCE ()
& Amp; # 8226; IsEmulator ()
& Amp; # 8226; IsSmartPhone ()
& Amp; # 8226; IsPockPC ()
& Amp; # 8226; IsTouchScreen ()
Source as follows:
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 does not 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 & amp; & amp;
// Windows Mobile 5.0 Smartphone emulator and earlier has a driver, but no touch screen.
! (IsSmartphone () & amp; & amp; IsEmulator () & amp; & amp; Environment.OSVersion.Version.Major & lt; 6);
}
else
return false;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment