PC Review


Reply
Thread Tools Rate Thread

Detect Mouse plug/unplug

 
 
Alessandro
Guest
Posts: n/a
 
      16th Jun 2009
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
 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      16th Jun 2009
I'd say that you probably can't. On our devices, we have a special class
that is sent via that notification for the mouse, specifically, being
inserted and removed.

It sounds to me like you should be saying something about what the actual
system behavior is. Does the device already handle showing and hiding the
cursor for you when a mouse is connected? It sounds like your answer is
"no". If that's the case, I'm not sure that Cursor.Show will do anything
for you. Give us a little more information about how the device actually
works, completely aside from your application, with respect to the mouse
cursor. That will probably tell us enough to suggest what you'll have to
do.

Paul T.

"Alessandro" <(E-Mail Removed)> wrote in message
news:604b90aa-40f4-408d-b4e9-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Alessandro
Guest
Posts: n/a
 
      16th Jun 2009
On Jun 16, 7:39*pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
> I'd say that you probably can't. *On our devices, we have a special class
> that is sent via that notification for the mouse, specifically, being
> inserted and removed.
>
> It sounds to me like you should be saying something about what the actual
> system behavior is. Does the device already handle showing and hiding the
> cursor for you when a mouse is connected? *It sounds like your answer is
> "no". *If that's the case, I'm not sure that Cursor.Show will do anything
> for you. *Give us a little more information about how the device actually
> works, completely aside from your application, with respect to the mouse
> cursor. *That will probably tell us enough to suggest what you'll have to
> do.
>
> Paul T.
>
> "Alessandro" <brambi...@elsyst.it> wrote in message
>
> news:604b90aa-40f4-408d-b4e9-(E-Mail Removed)...
>
> > 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


Hi Paul, thaks for your reply.

The mouse works fine and Cursor.Hide/Show works fine too.
I have a x86 device with some USB port. We have only one full screen
application.
The device have a touch screen.

I hope this informations help you to understand.
Thanks in advance!
Ale
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      16th Jun 2009
>Hi Paul, thaks for your reply.
>
>The mouse works fine and Cursor.Hide/Show works fine too.
>I have a x86 device with some USB port. We have only one full screen
>application.
>The device have a touch screen.
>
>I hope this informations help you to understand.
>Thanks in advance!
>Ale


No, that made things worse. The mouse cursor automatically appears and
disappears on the screen when you plug the mouse in or remove the mouse? If
so, what's the problem? Seems like your work to show/hide the cursor when
the mouse is present/absent is already done.

I understand fine about the touchscreen. What I'm trying to figure out is
whether you are trying to implement a system-level behavior, showing and
hiding the mouse cursor as a mouse is dynamically added or removed, or
trying to do something else that is not a system-level behavior but which I
don't understand.

Paul T.


 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      16th Jun 2009
That's certainly a system-level behavior that should come as a standard
behavior. If your device doesn't already do that, I'd be complaining the
the OEM's support channel.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


"Alessandro" <(E-Mail Removed)> wrote in message
news:85e831bf-5282-415e-8caa-(E-Mail Removed)...
On Jun 16, 7:39 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
> I'd say that you probably can't. On our devices, we have a special class
> that is sent via that notification for the mouse, specifically, being
> inserted and removed.
>
> It sounds to me like you should be saying something about what the actual
> system behavior is. Does the device already handle showing and hiding the
> cursor for you when a mouse is connected? It sounds like your answer is
> "no". If that's the case, I'm not sure that Cursor.Show will do anything
> for you. Give us a little more information about how the device actually
> works, completely aside from your application, with respect to the mouse
> cursor. That will probably tell us enough to suggest what you'll have to
> do.
>
> Paul T.
>
> "Alessandro" <brambi...@elsyst.it> wrote in message
>
> news:604b90aa-40f4-408d-b4e9-(E-Mail Removed)...
>
> > 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


Hi Paul, thaks for your reply.

The mouse works fine and Cursor.Hide/Show works fine too.
I have a x86 device with some USB port. We have only one full screen
application.
The device have a touch screen.

I hope this informations help you to understand.
Thanks in advance!
Ale


 
Reply With Quote
 
Alessandro
Guest
Posts: n/a
 
      16th Jun 2009
On Jun 16, 9:12*pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
> >Hi Paul, thaks for your reply.

>
> >Themouseworks fine and Cursor.Hide/Show works fine too.
> >I have a x86 device with some USB port. We have only one full screen
> >application.
> >The device have a touch screen.

>
> >I hope this informations help you to understand.
> >Thanks in advance!
> >Ale

>
> No, that made things worse. *Themousecursor automatically appears and
> disappears on the screen when you plug themousein or remove themouse? *If
> so, what's the problem? *Seems like your work to show/hide the cursor when
> themouseis present/absent is already done.
>
> I understand fine about the touchscreen. *What I'm trying to figure outis
> whether you are trying to implement a system-level behavior, showing and
> hiding themousecursor as amouseis dynamically added or removed, or
> trying to do something else that is not a system-level behavior but whichI
> don't understand.
>
> Paul T.


The mouse cursor doesn't automatically appears and disappears. It is
always showed.
I need show the cursor only when mouse is plugged and i need hide the
cursor when the mouse is not plugged.
I dont need to implement a system-level behavior. The device runs
always the same application. Into this application i need execute
Cursor.Show when a usb mouse is plug-in and i need execute Cursor.Hide
when the mouse is detach/not present. But, (with my application in
VB.NET) how can I detect the connection/disconnection of a USB mouse ?
Like you say, i need "showing and hiding the mouse cursor as a mouse
is dynamically added or removed" but i dont know C language therefore
system-level implementation is not good for me.

Thaks again for your patience.
Ale
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      16th Jun 2009
OK, then to really have it work "right", you'd want to change both the mouse
driver and the display driver, potentially. The display driver needs to
know itself whether there is a mouse attached and should not show the cursor
unless there is a mouse. The mouse driver should send a device notification
that indicates "Mouse" for attach and detach of the mouse. For this, I'd
recommend the following IClass value suggested by Steve Maillet a while
back:

#define DEVCLASS_MOUSE_GUID_STRING
TEXT("{FFBE5A05-87B4-4591-B067-CEBA6FAFD298}")
#define DEVCLASS_MOUSE_GUID { 0xFFBE5A05, 0x87B4, 0x4591, { 0xB0, 0x67,
0xCE, 0xBA, 0x6F, 0xAF, 0xD2, 0x98 } }

Call AdvertiseInterface on that value with TRUE or FALSE to indicate
connection/disconnect in the mouse driver.

You can then set up the display driver to, by default, not display the
cursor. The driver can create a thread to monitor for mouse connect and,
when it decides that there is a mouse connected, turn the cursor on.
Obviously, since you've already adjusted your application to look for the
mouse and since you are the only application ever visible on the screen, you
could bypass adjusting the display driver and just control the cursor for
your application. If any other application ever comes to the front, the
cursor will be ON, regardless of what you've done in your application,
though.

Paul T.

"Alessandro" <(E-Mail Removed)> wrote in message
news:b429d13c-39fb-4419-b100-(E-Mail Removed)...
On Jun 16, 9:12 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
> >Hi Paul, thaks for your reply.

>
> >Themouseworks fine and Cursor.Hide/Show works fine too.
> >I have a x86 device with some USB port. We have only one full screen
> >application.
> >The device have a touch screen.

>
> >I hope this informations help you to understand.
> >Thanks in advance!
> >Ale

>
> No, that made things worse. Themousecursor automatically appears and
> disappears on the screen when you plug themousein or remove themouse? If
> so, what's the problem? Seems like your work to show/hide the cursor when
> themouseis present/absent is already done.
>
> I understand fine about the touchscreen. What I'm trying to figure out is
> whether you are trying to implement a system-level behavior, showing and
> hiding themousecursor as amouseis dynamically added or removed, or
> trying to do something else that is not a system-level behavior but which
> I
> don't understand.
>
> Paul T.


The mouse cursor doesn't automatically appears and disappears. It is
always showed.
I need show the cursor only when mouse is plugged and i need hide the
cursor when the mouse is not plugged.
I dont need to implement a system-level behavior. The device runs
always the same application. Into this application i need execute
Cursor.Show when a usb mouse is plug-in and i need execute Cursor.Hide
when the mouse is detach/not present. But, (with my application in
VB.NET) how can I detect the connection/disconnection of a USB mouse ?
Like you say, i need "showing and hiding the mouse cursor as a mouse
is dynamically added or removed" but i dont know C language therefore
system-level implementation is not good for me.

Thaks again for your patience.
Ale


 
Reply With Quote
 
Alessandro
Guest
Posts: n/a
 
      16th Jun 2009
On Jun 16, 9:25*pm, "Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com>
wrote:
> That's certainly a system-level behavior that should come as a standard
> behavior. *If your device doesn't already do that, I'd be complaining the
> the OEM's support channel.
>
> --
>
> Chris Tacke, Embedded MVP
> OpenNETCF Consulting
> Giving back to the embedded communityhttp://community.OpenNETCF.com
>
> "Alessandro" <brambi...@elsyst.it> wrote in message
>
> news:85e831bf-5282-415e-8caa-(E-Mail Removed)...
> On Jun 16, 7:39 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
> no instrument no spam DOT com> wrote:
>
>
>
> > I'd say that you probably can't. On our devices, we have a special class
> > that is sent via that notification for the mouse, specifically, being
> > inserted and removed.

>
> > It sounds to me like you should be saying something about what the actual
> > system behavior is. Does the device already handle showing and hiding the
> > cursor for you when a mouse is connected? It sounds like your answer is
> > "no". If that's the case, I'm not sure that Cursor.Show will do anything
> > for you. Give us a little more information about how the device actually
> > works, completely aside from your application, with respect to the mouse
> > cursor. That will probably tell us enough to suggest what you'll have to
> > do.

>
> > Paul T.

>
> > "Alessandro" <brambi...@elsyst.it> wrote in message

>
> >news:604b90aa-40f4-408d-b4e9-(E-Mail Removed)...

>
> > > 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

>
> Hi Paul, thaks for your reply.
>
> The mouse works fine and Cursor.Hide/Show works fine too.
> I have a x86 device with some USB port. We have only one full screen
> application.
> The device have a touch screen.
>
> I hope this informations help you to understand.
> Thanks in advance!
> Ale


Then, modify the mouse driver is the only way (I suppose the mouse
driver - MOUHID.DLL - must send a system message when mouse is plugged/
unplugged). Right ?
Thanks
Ale
 
Reply With Quote
 
Alessandro
Guest
Posts: n/a
 
      17th Jun 2009
On Jun 16, 10:33*pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
> OK, then to really have it work "right", you'd want to change both the mouse
> driver and the display driver, potentially. *The display driver needs to
> know itself whether there is a mouse attached and should not show the cursor
> unless there is a mouse. *The mouse driver should send a device notification
> that indicates "Mouse" for attach and detach of the mouse. *For this, I'd
> recommend the following IClass value suggested by Steve Maillet a while
> back:
>
> #define DEVCLASS_MOUSE_GUID_STRING
> TEXT("{FFBE5A05-87B4-4591-B067-CEBA6FAFD298}")
> #define DEVCLASS_MOUSE_GUID * { 0xFFBE5A05, 0x87B4, 0x4591, { 0xB0, 0x67,
> 0xCE, 0xBA, 0x6F, 0xAF, 0xD2, 0x98 } }
>
> Call AdvertiseInterface on that value with TRUE or FALSE to indicate
> connection/disconnect in the mouse driver.
>
> You can then set up the display driver to, by default, not display the
> cursor. *The driver can create a thread to monitor for mouse connect and,
> when it decides that there is a mouse connected, turn the cursor on.
> Obviously, since you've already adjusted your application to look for the
> mouse and since you are the only application ever visible on the screen, you
> could bypass adjusting the display driver and just control the cursor for
> your application. *If any other application ever comes to the front, the
> cursor will be ON, regardless of what you've done in your application,
> though.
>
> Paul T.
>
> "Alessandro" <brambi...@elsyst.it> wrote in message
>
> news:b429d13c-39fb-4419-b100-(E-Mail Removed)...
> On Jun 16, 9:12 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
> no instrument no spam DOT com> wrote:
>
>
>
> > >Hi Paul, thaks for your reply.

>
> > >Themouseworks fine and Cursor.Hide/Show works fine too.
> > >I have a x86 device with some USB port. We have only one full screen
> > >application.
> > >The device have a touch screen.

>
> > >I hope this informations help you to understand.
> > >Thanks in advance!
> > >Ale

>
> > No, that made things worse. Themousecursor automatically appears and
> > disappears on the screen when you plug themousein or remove themouse? If
> > so, what's the problem? Seems like your work to show/hide the cursor when
> > themouseis present/absent is already done.

>
> > I understand fine about the touchscreen. What I'm trying to figure out is
> > whether you are trying to implement a system-level behavior, showing and
> > hiding themousecursor as amouseis dynamically added or removed, or
> > trying to do something else that is not a system-level behavior but which
> > I
> > don't understand.

>
> > Paul T.

>
> The mouse cursor doesn't automatically appears and disappears. It is
> always showed.
> I need show the cursor only when mouse is plugged and i need hide the
> cursor when the mouse is not plugged.
> I dont need to implement a system-level behavior. The device runs
> always the same application. Into this application i need execute
> Cursor.Show when a usb mouse is plug-in and i need execute Cursor.Hide
> when the mouse is detach/not present. But, (with my application in
> VB.NET) how can I detect the connection/disconnection of a USB mouse ?
> Like you say, i need "showing and hiding the mouse cursor as a mouse
> is dynamically added or removed" but i dont know C language therefore
> system-level implementation is not good for me.
>
> Thaks again for your patience.
> Ale


Thank Paul and Chris !

About Paul's reply:

I will bypass adjusting the display driver and I will just control the
cursor for
my application. Then I must modify only the mouse driver. But I
unfortunately need further help :-(
I use standard CEPC mouse and keyboard driver. Then where I can/must
insert the #Define and where i can/must call
the AdvertiseInterface ?

Thankyou very much
Ale
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      17th Jun 2009
Well, you have to modify the MOUHID component, so you have to clone that and
put it in your platform. The information on how to do that is, to some
extent, in the help and you can find other documents on the topic online,
I'm sure. Somewhere near the top, you'll probably add an #include like
this:

// PGT: Get the GUID for the mouse device class that we will
// advertise when the mouse is detected.
#include <devclassmouse.h>

where that header file includes the information I gave you in the last
message. Then, assuming you are using the Microsoft driver, in the function
HIDDeviceAttach(), you'll need to add code like this:

// PGT: Notify the system that there is a new mouse device
// attaching. Advertise our custom GUID for the device,
// DEVCLASS_MOUSE_GUID.
DEBUGMSG( 1, ( TEXT( "USBMouse::HidDeviceAttach - Got a mouse. Advertise
it.\r\n" ) ) );

{
GUID devclass = DEVCLASS_MOUSE_GUID;
if ( AdvertiseInterface( &devclass, _T( "USBMouse" ), TRUE ) )
{
DEBUGMSG( 1, ( TEXT( "USBMouse::HidDeviceAttach - Successfully advertised
interface %s.\r\n" ), DEVCLASS_MOUSE_GUID_STRING ) );
}
else
{
DEBUGMSG( 1, ( TEXT( "USBMouse::HidDeviceAttach - AdvertiseInterface
failed %s. Err = 0x%x.\r\n" ), DEVCLASS_MOUSE_GUID_STRING,
GetLastError() ) );
}
}

I do it just before the MouseThreadProc thread is created. Then, in
HIDDeviceNotifications(), you need to notify that the mouse is removed in
the HID_CLOSE_DEVICE case. There, you'll do something like this:

// PGT: Notify everyone that a mouse has been
// disconnected.
DEBUGMSG( 1, ( TEXT( "USBMouse::HIDDeviceNotifications - Mouse removed.
Advertise that.\r\n" ) ) );

{
GUID devclass = DEVCLASS_MOUSE_GUID;
if ( AdvertiseInterface( &devclass, _T( "USBMouse" ), FALSE ) )
{
DEBUGMSG( 1, ( TEXT( "USBMouse::HIDDeviceNotifications - Successfully
deadvertised interface %s.\r\n" ), DEVCLASS_MOUSE_GUID_STRING ) );
}
else
{
DEBUGMSG( 1, ( TEXT( "USBMouse::HIDDeviceNotifications -
AdvertiseInterface failed %s. Err = 0x%x.\r\n" ),
DEVCLASS_MOUSE_GUID_STRING, GetLastError() ) );
}
}

I do this just before FreeHidMouse() is called in the Microsoft code.

Paul T.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
network plug is unplug Rajan Windows XP Networking 3 4th May 2009 12:21 AM
Detect Plug Unplug of a device Anoj Microsoft VB .NET 1 10th Sep 2006 11:47 AM
USB plug and unplug cause PC auto reboot Peter Kiang Windows XP General 0 21st Oct 2005 04:48 PM
Unplug and plug USB device as non admin user acvlee Windows XP Hardware 0 19th Sep 2005 04:40 AM
No devices in plug / unplug wizard.... Tim Microsoft Windows 2000 Hardware 1 16th Jun 2004 01:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:37 AM.