2010-01-16 87 views
2

我想知道是否有人可以为我提供添加振动到按钮的单击事件的提示。我一直在环顾四周,但只使用窗口注册表找到类似的例子 - 但是我希望避免在可能的情况下避免注入注册表。.Net Compact Framework - 为按钮单击事件添加振动

任何人都可以提供一些示例代码来实现此目的(C#或VB.Net)?

谢谢。

更新: jball提供的代码就像一个魅力。 我所谓的代码,从而实现短振动如下:

Private Sub btnMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
handles btnMute.Click 
      SetVibrate(1) 
      Thread.Sleep(50) 'how long should the vibration last 
      SetVibrate(0) 
end sub 

真正伟大的作品!

回答

2

它通过LED API访问。从here

在大多数设备的振动设为 到LED装置1

下面是来自相同的源代码示例。

Private Structure NLED_SETTINGS_INFO 
    Public LedNum As Integer 
    Public OffOnBlink As Integer 
    Public TotalCycleTime As Integer 
    Public OnTime As Integer 
    Public OffTime As Integer 
    Public MetaCycleOn As Integer 
    Public MetaCycleOff As Integer 
End Structure 

<DllImport("Coredll")> _ 
Private Shared Function NLedSetDevice(ByVal deviceId As Integer, ByRef info 
              As NLED_SETTINGS_INFO) As Boolean 
End Function 

Private Shared Sub SetVibrate(ByVal state As Boolean) 
    Dim info As New NLED_SETTINGS_INFO() 
    info.LedNum = 1 
    info.OffOnBlink = If(state, 1, 0) 
    NLedSetDevice(1, info) 
End Sub 
+0

非常好!我只是尝试过它,它像魅力一样工作。 – moster67 2010-01-16 10:50:51