gpsdevicestate.cs

来自「清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码」· CS 代码 · 共 104 行

CS
104
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#region Using directives

using System;
using System.Runtime.InteropServices;

#endregion

namespace Microsoft.WindowsMobile.Samples.Location
{
    public enum GpsServiceState : int
    {
        Off = 0,
        On = 1,
        StartingUp = 2, 
        ShuttingDown = 3,
        Unloading = 4,
        Uninitialized = 5,
        Unknown = -1
    }

    /// <summary>
    /// GpsDeviceState holds the state of the gps device and the friendly name if the 
    /// gps supports them.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public class GpsDeviceState
    {
        public const int GpsDeviceStructureSize = 216;

        private GPS_DEVICE device;

        /// <summary>
        /// State of the GPS Intermediate Driver service
        /// </summary>
        public GpsServiceState ServiceState
        {
            get {return (GpsServiceState)device.dwServiceState;}
        }

        /// <summary>
        /// Status of the actual GPS device driver.
        /// </summary>
        public GpsServiceState DeviceState
        {
            get { return (GpsServiceState)device.dwDeviceState; }
        }

        public string DriverPrefix
        {
            get { return device.szGPSDriverPrefix; }
        }

        public string MultiplexPrefix
        {
            get { return device.szGPSMultiplexPrefix; }
        }
        /// <summary>
        /// Friendly name of the real GPS device we are currently using.
        /// </summary>
        public string FriendlyName
        {
            get {return device.szGPSFriendlyName;}
        }

        /// <summary>
        /// Constructor of GpsDeviceState.
        /// </summary>
        internal GpsDeviceState(GPS_DEVICE device)
        {
            this.device = device;
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct GPS_DEVICE
    {
        internal const int GPS_MAX_PREFIX_NAME = 16;
        internal const int GPS_MAX_FRIENDLY_NAME = 64;

        public int dwVersion;
        public int dwSize;
        public int dwServiceState;
        public int dwDeviceState;
        public long ftLastDataReceived;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=GPS_MAX_PREFIX_NAME)]
        public string szGPSDriverPrefix;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=GPS_MAX_PREFIX_NAME)]
        public string szGPSMultiplexPrefix;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=GPS_MAX_FRIENDLY_NAME)]
        public string szGPSFriendlyName;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?