我已经在我的表单中添加了一个SysInfo控件,并且在插入或拔出USB读卡器时尝试生成短信。
Private Sub SysInfo1_ConfigChanged(ByVal OldConfigNum As Long, ByVal NewConfigNum As Long)
ShowText "The system configuration has changed"
End Sub
我已尝试使用DisplayChanged事件进行类似的测试消息,并在更改显示器分辨率时成功接收该消息,但我不能在我的生活中获得上述功能。我的印象是,添加/删除USB设备时应该发生ConfigChanged事件。我将SysInfo.ocx包含在Vista机器上的应用程序和测试中。感谢
答案 0 :(得分:2)
使用 SysInfo_DeviceArrival 事件检测USB驱动器的插入。 SysInfo_DeviceRemoveComplete 会在删除后触发。
SysInfo控件有很多事件,所以我编写了一个测试程序来查看发生了什么事件。我经常在使用之前没有使用的控件时这样做。运行SysInfoControl的程序包含在下面。
我是通过使用VB6代码编辑窗口顶部的下拉列表来实现的:在左侧选择SysInfo控件,选择右侧显示的每个事件。为每个程序添加一个Debug.Print语句,运行项目,然后插入USB设备。
此外,如果在窗体设计器中选择SysInfo控件,然后按F1,则应显示MSDN库帮助,其中包括所有事件的说明以及如何解释其参数。至少,它在我的机器上。 (当人们这么说时我讨厌它,但它适用于此,因为MSDN文档必须单独安装。)
如果这不起作用,我在网上找到了文档here。
Option Explicit
Private Sub SysInfo_ConfigChangeCancelled()
Debug.Print Now() & ": " & "SysInfo_ConfigChangeCancelled"
End Sub
Private Sub SysInfo_ConfigChanged(ByVal OldConfigNum As Long, ByVal NewConfigNum As Long)
Debug.Print Now() & ": " & "SysInfo_ConfigChanged"
End Sub
Private Sub SysInfo_DeviceArrival(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Debug.Print Now() & ": " & "SysInfo_DeviceArrival"
End Sub
Private Sub SysInfo_DeviceOtherEvent(ByVal DeviceType As Long, ByVal EventName As String, ByVal DataPointer As Long)
Debug.Print Now() & ": " & "SysInfo_DeviceOtherEvent"
End Sub
Private Sub SysInfo_DeviceQueryRemove(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long, Cancel As Boolean)
Debug.Print Now() & ": " & "SysInfo_DeviceQueryRemove"
End Sub
Private Sub SysInfo_DeviceQueryRemoveFailed(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Debug.Print Now() & ": " & "SysInfo_DeviceQueryRemoveFailed"
End Sub
Private Sub SysInfo_DeviceRemoveComplete(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Debug.Print Now() & ": " & "SysInfo_DeviceRemoveComplete"
End Sub
Private Sub SysInfo_DeviceRemovePending(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Debug.Print Now() & ": " & "SysInfo_DeviceRemovePending"
End Sub
Private Sub SysInfo_DevModeChanged()
Debug.Print Now() & ": " & "SysInfo_DevModeChanged"
End Sub
Private Sub SysInfo_DisplayChanged()
Debug.Print Now() & ": " & "SysInfo_DisplayChanged"
End Sub
Private Sub SysInfo_PowerQuerySuspend(Cancel As Boolean)
Debug.Print Now() & ": " & "SysInfo_PowerQuerySuspend"
End Sub
Private Sub SysInfo_PowerResume()
Debug.Print Now() & ": " & "SysInfo_PowerResume"
End Sub
Private Sub SysInfo_PowerStatusChanged()
Debug.Print Now() & ": " & "SysInfo_PowerStatusChanged"
End Sub
Private Sub SysInfo_PowerSuspend()
Debug.Print Now() & ": " & "SysInfo_PowerSuspend"
End Sub
Private Sub SysInfo_QueryChangeConfig(Cancel As Boolean)
Debug.Print Now() & ": " & "SysInfo_QueryChangeConfig"
End Sub
Private Sub SysInfo_SettingChanged(ByVal Item As Integer)
Debug.Print Now() & ": " & "SysInfo_SettingChanged"
End Sub
Private Sub SysInfo_SysColorsChanged()
Debug.Print Now() & ": " & "SysInfo_SysColorsChanged"
End Sub
Private Sub SysInfo_TimeChanged()
Debug.Print Now() & ": " & "SysInfo_TimeChanged"
End Sub
答案 1 :(得分:1)
为什么要运送额外的控件?我建议看看Karl Peterson的SysInfo示例:http://vb.mvps.org/samples/SysInfo/ CSysInfoDevice类将监视设备事件。