VB高手进,VB程序详细解释。
Option Explicit
Implements iSubclass
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String _
) As Long
Private m_clsSubcls As cSubclass
Private Sub cmdEject_Click()
If EjectDevice(lvwDrives.SelectedItem.Tag) Then
MsgBox "OK,USB设备安全弹出,您可以放心拔出U盘!", vbInformation, "U盘拔出"
Else
MsgBox "该驱动器不支持弹出 " & lvwDrives.SelectedItem.Tag & "!", vbExclamation, "提示"
End If
End Sub
Private Sub Form_Load()
Set m_clsSubcls = New cSubclass
m_clsSubcls.Subclass Me.hwnd, Me
m_clsSubcls.AddMsg Me.hwnd, WM_DEVICECHANGE
RefreshDriveList
End Sub
Private Sub Form_Unload(Cancel As Integer)
m_clsSubcls.Terminate
End Sub
Private Sub RefreshDriveList()
Dim strDriveBuffer As String
Dim strDrives() As String
Dim i As Long
Dim udtInfo As DEVICE_INFORMATION
strDriveBuffer = Space(240)
strDriveBuffer = Left$(strDriveBuffer, GetLogicalDriveStrings(Len(strDriveBuffer), strDriveBuffer))
strDrives = Split(strDriveBuffer, Chr$(0))
lvwDrives.ListItems.Clear
For i = 0 To UBound(strDrives) - 1
With lvwDrives.ListItems.Add(Text:=strDrives(i))
udtInfo = GetDevInfo(strDrives(i))
If udtInfo.Valid Then
Select Case udtInfo.BusType
Case BusTypeUsb: .SubItems(1) = "USB"
Case BusType1394: .SubItems(1) = "1394"
Case BusTypeAta: .SubItems(1) = "ATA"
Case BusTypeAtapi: .SubItems(1) = "ATAPI"
Case BusTypeFibre: .SubItems(1) = "Fibre"
Case BusTypeRAID: .SubItems(1) = "RAID"
Case BusTypeScsi: .SubItems(1) = "SCSI"
Case BusTypeSsa: .SubItems(1) = "SSA"
Case BusTypeUnknown: .SubItems(1) = "未知"
End Select
.SubItems(2) = IIf(udtInfo.Removable, "是", "否")
.SubItems(3) = Trim$(udtInfo.VendorID & " " & udtInfo.ProductID & " " & udtInfo.ProductRevision)
.Tag = strDrives(i)
End If
End With
Next
End Sub
Private Sub iSubclass_WndProc(ByVal bBefore As Boolean, bHandled As Boolean, lReturn As Long, ByVal lng_hWnd As Long, ByVal uMsg As eMsg, ByVal wParam As Long, ByVal lParam As Long, lParamUser As Long)
If uMsg = WM_DEVICECHANGE Then RefreshDriveList
End Sub
Private Sub lvwDrives_BeforeLabelEdit(Cancel As Integer)
End Sub
麻烦逐句解释,谢谢!分数可再加。
追问:可不可以再详细点啊?谢谢!!!再给多你100分,谢谢