WM手机,如何实现震动
2009-05-20 22:39
489 查看
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
{
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
相关文章推荐
- WM手机,如何实现震动?
- .Net语言 APP开发平台——Smobiler学习日志:在手机应用开发中如何快速实现应用间的分享功能
- Oracle 10g如何实现 wm_concat函数(转)
- WM手机如何通过蓝牙连接ActiveSync
- js如何实现图片一直停留在手机屏幕底部
- EasyPusher手机直播推送是如何实现后台直播推送的
- 如何通过代码实现进入到手机的设置页面(比如开启gps设置的页面)
- 如何实现android手机摄像头的的自动对焦
- 如何在手机上实现高精度及自适应多种场景的计步器算法
- android:如果手机安装了app则打开一个activity,如果没有安装则去到android market如何在HTML页面实现
- Android 手机震动功能实现
- Unity实现手机震动
- Android--SensorEventListener和AudioManager实现根据条件转换手机震动和响铃
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(一)----初始化显示的高分榜
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(五)----使用TextField 输入并调整排名
- Windows 2000/XP下如何实现红外手机上网?
- 如何使用Androidstudio实现中英手机信息页面
- Unity如何调用安卓手机摄像头实现拍照和录像
- 如何实现android手机摄像头的的自动对焦
- 如何实现手机注册验证