A
Alessandro
Hi to all
I develop with VB.NET 2005 on WinCE 6.0 platform. By default the USB
mouse is not plugged and the cursor is hidden. I want to show the
cursor when the mouse is plugged and hide the cursor when the mouse is
unplugged.
To show/hide the cursor I can use the Cursor.Show and Cursor.Hide
methods. To detect plug/unplug I have tried to use the
OpenNETCF.WindowsCE.DeviceStatusMonitor class. This is my code:
Public Class frmMain
Dim WithEvents monitor As OpenNETCF.WindowsCE.DeviceStatusMonitor
= New OpenNETCF.WindowsCE.DeviceStatusMonitor(DeviceClass.Any, False)
Delegate Sub AddMessage(ByVal msg As String)
Private myDelegate As AddMessage = New AddMessage(AddressOf
ShowMessage)
Private Sub StatusChanged(ByVal sender As Object, ByVal e As
DeviceNotificationArgs) Handles monitor.DeviceNotification
Dim message As String = String.Format("Device '{0}' has been
{1}.", e.DeviceName, IIf(e.DeviceAttached, "inserted",
"removed").ToString)
message &= vbCrLf & "Device Class = " & e.DeviceClass.ToString
& " - DeviceInterfaceGUID = " & e.DeviceInterfaceGUID.ToString
Invoke(myDelegate, message)
End Sub
Private Sub ShowMessage(ByVal msg As String)
txtMsg.Text &= msg & vbCrLf
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStart.Click
If monitor.Active Then Exit Sub
monitor.StartStatusMonitoring()
lblMonitor.Text = "--> M O N I T O R I N G <--"
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStop.Click
If Not monitor.Active Then Exit Sub
monitor.StopStatusMonitoring()
lblMonitor.Text = "--> S T O P P E D <--"
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
monitor.Dispose()
End Sub
End Class
When I plug the USB mouse I receive this message:
"Device 'HID1:' has been inserted.
Device Class = StreamDevice - DeviceInterfaceGUID =
f8a6ba98-087a-43ac-a9d8-b7f13c5bae31
BUT if i plug an USB keyboard before the USB mouse I receive two
message for the keyboard and no message when I plug the mouse. The two
message (keyboard) are:
Device 'HID1:' has been inserted.
Device Class = StreamDevice - DeviceInterfaceGUID =
f8a6ba98-087a-43ac-a9d8-b7f13c5bae31
Device 'KBD1:' has been inserted.
Device Class = Keyboard - DeviceInterfaceGUID = cbe6ddf2-
f5d4-4e16-9f61-4ccc0b6695f3
How can I detect the connection/disconnection of a USB mouse WITHOUT
modify the mouse driver ?
(I don't program with C-language and it is difficult for me to modify
the driver).
Thankyou very much!
Ale
I develop with VB.NET 2005 on WinCE 6.0 platform. By default the USB
mouse is not plugged and the cursor is hidden. I want to show the
cursor when the mouse is plugged and hide the cursor when the mouse is
unplugged.
To show/hide the cursor I can use the Cursor.Show and Cursor.Hide
methods. To detect plug/unplug I have tried to use the
OpenNETCF.WindowsCE.DeviceStatusMonitor class. This is my code:
Public Class frmMain
Dim WithEvents monitor As OpenNETCF.WindowsCE.DeviceStatusMonitor
= New OpenNETCF.WindowsCE.DeviceStatusMonitor(DeviceClass.Any, False)
Delegate Sub AddMessage(ByVal msg As String)
Private myDelegate As AddMessage = New AddMessage(AddressOf
ShowMessage)
Private Sub StatusChanged(ByVal sender As Object, ByVal e As
DeviceNotificationArgs) Handles monitor.DeviceNotification
Dim message As String = String.Format("Device '{0}' has been
{1}.", e.DeviceName, IIf(e.DeviceAttached, "inserted",
"removed").ToString)
message &= vbCrLf & "Device Class = " & e.DeviceClass.ToString
& " - DeviceInterfaceGUID = " & e.DeviceInterfaceGUID.ToString
Invoke(myDelegate, message)
End Sub
Private Sub ShowMessage(ByVal msg As String)
txtMsg.Text &= msg & vbCrLf
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStart.Click
If monitor.Active Then Exit Sub
monitor.StartStatusMonitoring()
lblMonitor.Text = "--> M O N I T O R I N G <--"
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStop.Click
If Not monitor.Active Then Exit Sub
monitor.StopStatusMonitoring()
lblMonitor.Text = "--> S T O P P E D <--"
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
monitor.Dispose()
End Sub
End Class
When I plug the USB mouse I receive this message:
"Device 'HID1:' has been inserted.
Device Class = StreamDevice - DeviceInterfaceGUID =
f8a6ba98-087a-43ac-a9d8-b7f13c5bae31
BUT if i plug an USB keyboard before the USB mouse I receive two
message for the keyboard and no message when I plug the mouse. The two
message (keyboard) are:
Device 'HID1:' has been inserted.
Device Class = StreamDevice - DeviceInterfaceGUID =
f8a6ba98-087a-43ac-a9d8-b7f13c5bae31
Device 'KBD1:' has been inserted.
Device Class = Keyboard - DeviceInterfaceGUID = cbe6ddf2-
f5d4-4e16-9f61-4ccc0b6695f3
How can I detect the connection/disconnection of a USB mouse WITHOUT
modify the mouse driver ?
(I don't program with C-language and it is difficult for me to modify
the driver).
Thankyou very much!
Ale