How to detect device arrival?

幫朋友找資料找到的,順道貼上來
我沒試過
不過我想應該是可以運行吧~~
以 VFP 或 VB 來說,是利用 sysinfo 這個 Active X control .
主要是攔截 DeviceArrival 這個 event
詳細的範例可以參考DeviceArrival Event Example
雖然他是 VB 的範例,不過看起來應該是很好改成 VFP 才是…

Private Sub SysInfo1_DeviceArrival(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
  Debug.Print "DeviceArrival"
  Debug.Print "devicetype " & DeviceType
  Debug.Print "DeviceID " & GetDrive(DeviceType, DeviceID)
  Debug.Print "DeviceName " & DeviceName
  Debug.Print "DeviceData " & DeviceData
End Sub

Private Function GetDrive(devType As Long, devID As Long) As String
  Select Case devType
    Case 0 To 1 ' returns null
      GetDrive = devID
      Exit Function
    Case 3 To 4 ' returns null
      GetDrive = devID
      Exit Function
    Case 2 ' logical drive.
      ' Create an array for the possible drive numbers returned by
      ' deviceID
      Dim drives(25) ' A-Z
      Dim dvNum As Long ' Possible bit values.
      Dim i As Integer
      dvNum = 1
      drives(0) = 1
      ' Populate with bit values.
      For i = 1 To 25
        dvNum = dvNum * 2
        drives(i) = dvNum
      Next i
      For i = 0 To 25
        If drives(i) = devID Then
          GetDrive = "Drive: " & Chr(i + 65)
          Exit Function
        End If
      Next I
    Case Else ' Other unexpected returns
      Debug.Print devType, devID
    End Select
End Function