VB6获取USB设备的拔出信息每次软件开启的第一次都不灵,什么原因呀?
Public Function WndProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long '消息拦截 当有消息时候会在这里出现
If msg = WM_DEVICECHANGE Then '当消息是 磁盘发生改变
Select Case Menu
Case NET_MENU
DeviceNet.tmrUSB.Enabled = True: DoEvents
Case LED_MENU
LEDsignal.tmrConnect.Enabled = True
Case CH_MENU
SelectCH.tmrTelCom.Enabled = True: DoEvents
Case Else
End Select
End If
WndProc = CallWindowProcA(lpPrev, hWnd, msg, wParam, lParam) '返回消息给系统否则系统所有消息都被拦截 你的电脑几乎就是废了 关机都不行
End Function
'使用定时器的查询来获取是插入,还是拔出。
Private Sub tmrConnect_Timer() '查检USB状态
Dim i As Integer
Call ConnectRMC
If FindTheHid = True Then
tmrConnect.Enabled = False: DoEvents
Label5.Caption = "请勿移动协调器!"
Call Led_On(1, GREEN)
tmrData.Enabled = True: DoEvents '数据收发
Else
Label5.Caption = "请接入协调器!"
If Check(1) = 1 Then
Call Led_On(1, RED)
Else
Call Led_On(1, BLACK)
End If
ShowWindow Me.hWnd, SW_RESTORE
tmrData.Enabled = False: DoEvents
'tmrConnect.Enabled = True: DoEvents
End If
End Sub