首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么判断插入的移动硬盘的盘符(不是u盘,是移动硬盘)

2012-01-11 
如何判断插入的移动硬盘的盘符(不是u盘,是移动硬盘)?如题,用getdrivetype不能识别本地硬盘和移动硬盘,两个

如何判断插入的移动硬盘的盘符(不是u盘,是移动硬盘)?
如题,用getdrivetype不能识别本地硬盘和移动硬盘,两个类型一样

[解决办法]
我知道~~加分吧~~
[解决办法]
啊|~~~
呵呵。。。

移动硬盘的盘符是怎么排列的,没用过。。。。。。

不过你可以去我的BLOG上看看判断U盘那个,,,是拦截的消息。。。。。。。估计移动硬盘插入也有对应消息发送到各个窗口吧。。
[解决办法]
to 陈辉:
主要问题是怎么判断现在移动硬盘是否已经插上了,判断出来这样遍历出来的磁盘盘符才是正确的。把代码贴出来,马上加分!

用 OnDeviceChange API:

Option Explicit

Private Type DEV_BROADCAST_HDR
dbch_size As Long
dbch_devicetype As Long
dbch_reserved As Long
End Type

Private Type DEV_BROADCAST_VOLUME
DBCV_Size As Long
DBCV_DeviceType As Long
DBCV_Reserved As Long
DBCV_UnitMask As Long
DBCV_Flags As Integer
End Type

Public Type AUTO_RUN
Flags As String
End Type

Private Declare Function CallWindowProc Lib "user32 " _
Alias "CallWindowProcA " _
(ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, _
ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32 " _
Alias "SetWindowLongA " _
(ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal wNewWord As Long) As Long

Private Const GWL_WNDPROC As Long = (-4)
Private Const DBT_DEVICEARRIVAL As Long = 32768
Private Const DBT_DEVICEREMOVECOMPLETE As Long = 32772
Private Const DBT_DEVTYP_VOLUME As Long = &H2
Public Const WM_CLOSE As Long = &H10
Private Const WM_DEVICECHANGE As Long = &H219

Public DeviceCallBack As Long

'在你的主窗体调用这个函数
Public Sub StartUSBWatch(ByVal hWnd As Long)
DeviceCallBack = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf OnDeviceChange)
End Sub

'退出程序时调用这个函数
Public Sub StopUSBWatch(ByVal hWnd As Long)
DeviceCallBack = SetWindowLong(hWnd, GWL_WNDPROC, DeviceCallBack)
End Sub

Public Function OnDeviceChange(ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

If Msg = WM_DEVICECHANGE Then
'在这里添加你的代码
End If
OnDeviceChange = CallWindowProc(DeviceCallBack, hWnd, Msg, wParam, lParam)
End Function

热点排行