利用C#开发Pocket PC程序,想在程序里调用设备的震动功能,至少再wm5中还没有这样的API,上网查了不少例子,都只能再c++下调用。既然这样,那唯一的办法是运用P/Invoke了,在“coredll.dll”中有这样两个函数
            BOOL WINAPI NLedGetDeviceInfo( UINT nInfoId, void *pOutput ); 
            BOOL WINAPI NLedSetDevice( UINT nDeviceId, void *pInput ); 

    NLedGetDeviceInfo是获得LED数量,NLedSetDevice是来设置LED状态的,我们只有通过它来启动或者关闭Pocket PC设备的震动与否。说明一下:一般PPC设备都有两个LED,一个就是扬声器0(Radio LED),另一个则是振动器1(Vibrator)了。在我的PPC设备上发现第二个是Vibrator,不知道是不是所有的PPC都是这样子的。后来查到“On the HTC Himalaya the vibration device is implemented at index 1。”也就是HTC内核的都是1.

在.NET Compact Framework调用PPC设备的震动功能using System;
在.NET Compact Framework调用PPC设备的震动功能
using System.Collections.Generic;
在.NET Compact Framework调用PPC设备的震动功能
using System.Text;
在.NET Compact Framework调用PPC设备的震动功能
using System.Runtime.InteropServices;
在.NET Compact Framework调用PPC设备的震动功能
using System.Threading;
在.NET Compact Framework调用PPC设备的震动功能

在程序里调用
LED led=new LED();
led.SetLedStatus(LED.Status.ON,500);//震动500毫秒

以上就是自己通过P/Invoke来实现震动效果,还有一段文字值得注意的:
for example some devices contain a notification Led at position 0 and a vibration device at position 5. There is no way to programmatically determine the index of the vibration device, you can only determine the overall count of devices. Also the vibration device can only be turned on or off so the Blink setting behaves exactly as On would.

当然你可以直接使用OpenNETCF的类库,如下:

OpenNETCF.Notification.Led led = new OpenNETCF.Notification.Led();
//turn on vibration

led.SetLedStatus(1, OpenNETCF.Notification.Led.LedState.On);

//turn off vibration

led.SetLedStatus(1, OpenNETCF.Notification.Led.LedState.Off);

相关文章:

  • 2021-09-08
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-01-23
  • 2021-08-27
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2021-11-13
  • 2021-07-01
  • 2022-12-23
  • 2022-01-31
  • 2021-05-16
  • 2021-12-19
相关资源
相似解决方案