您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: