• WM手机,如何实现震动


    public class LedLib
        {
            private int m_count;
            private const int NLED_COUNT_INFO_ID = 0;
            private const int NLED_SUPPORTS_INFO_ID = 1;

            public LedLib()
            {
                NLED_COUNT_INFO pOutput = new NLED_COUNT_INFO();
                if (!NLedGetDeviceCount(0, ref pOutput))
                {
                    throw new Exception("震动模块初始化错误!");
                }
                this.m_count = (int)pOutput.cLeds;
            }

            [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
            private static extern bool NLedGetDeviceCount(short nID, ref NLED_COUNT_INFO pOutput);
            [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
            private static extern bool NLedGetDeviceSupports(short nID, ref NLED_SUPPORTS_INFO pOutput);
            [DllImport("coredll.dll")]
            private static extern bool NLedSetDevice(short nID, ref NLED_SETTINGS_INFO pOutput);
            public void SetLedStatus(uint led, LedState newState)
            {
                NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO();
                pOutput.LedNum = led;
                pOutput.OffOnBlink = (int)newState;
                bool flag = NLedSetDevice(2, ref pOutput);
            }

            public enum LedState
            {
                Off,
                On,
                Blink
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_COUNT_INFO
            {
                public uint cLeds;
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_SETTINGS_INFO
            {
                public uint LedNum;
                public int OffOnBlink;
                public int TotalCycleTime;
                public int OnTime;
                public int OffTime;
                public int MetaCycleOn;
                public int MetaCycleOff;
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_SUPPORTS_INFO
            {
                public uint LedNum;
                public int lCycleAdjust;
                public bool fAdjustTotalCycleTime;
                public bool fAdjustOnTime;
                public bool fAdjustOffTime;
                public bool fMetaCycleOn;
                public bool fMetaCycleOff;
            }
        }

            /// <summary>
            /// 实现震动
            /// </summary>
            /// <param name="setTimes">震动毫秒数</param>
            public static void Play(int setTimes)
            {
                try
                {
                    LedLib led = new LedLib();
                    led.SetLedStatus(1, LedLib.LedState.On);
                    Thread.Sleep(setTimes);
                    led.SetLedStatus(1, LedLib.LedState.Off);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }

     

    转:http://blog.csdn.net/zhaojiangang/archive/2009/01/12/3760993.aspx

  • 相关阅读:
    重要:VC DLL编程
    VC++程序员如何做好界面
    复习二叉搜索树作的几道题
    eclipse JAVA反编译
    秒,毫秒,微秒,纳秒,皮秒,飞秒
    redis实现tomcat集群session共享
    redis启用持久化
    Spring
    Spring scope
    FastJSON 使用
  • 原文地址:https://www.cnblogs.com/moses/p/1472884.html
Copyright © 2020-2023  润新知