Code: Select all
Imports Microsoft.Win32
Private WM_DEVICECHANGE As Integer = &H219
Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = &H19
DBT_CONFIGCHANGED = &H18
DBT_CUSTOMEVENT = &H8006
DBT_DEVICEARRIVAL = &H8000
DBT_DEVICEQUERYREMOVE = &H8001
DBT_DEVICEQUERYREMOVEFAILED = &H8002
DBT_DEVICEREMOVECOMPLETE = &H8004
DBT_DEVICEREMOVEPENDING = &H8003
DBT_DEVICETYPESPECIFIC = &H8005
DBT_DEVNODES_CHANGED = &H7
DBT_QUERYCHANGECONFIG = &H17
DBT_USERDEFINED = &HFFFF
End Enum
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
'A USB device arrived
If MyPMDUtils.PacemakerInfo.PacemakerDrive = "" Then
'Pacemaker was not previously connected, so let's check if it is now
MyPMDUtils.FindPacemakerDrive()
if (MyPMDUtils.PacemakerInfo.PacemakerPresent) then
'Pacemaker has just been plugged in!
end if
End If
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
'A USB device was removed
If MyPMDUtils.PacemakerInfo.PacemakerDrive <> "" Then
'Pacemaker was previously connected, so let's check if it still is
MyPMDUtils.CheckPacemakerDriveStillPresent()
if (not MyPMDUtils.PacemakerInfo.PacemakerPresent) then
'Pacemaker has just been unplugged!
end if
End If
End Select
End If
MyBase.WndProc(m)
End Sub