- GUICreate('磁盘监控')
- Global $iLb = GUICtrlCreateLabel('', 50, 10, 300, 20, 0x201)
- Global $iEdit = GUICtrlCreateEdit('', 50, 30, 300, 320)
- _DeviceInfo()
- GUISetState()
- GUIRegisterMsg(537, '_WM_DEVICECHANGE')
- While GUIGetMsg() <> -3
- WEnd
- Exit
- Func _DeviceInfo()
- Local $iMask = DllCall('kernel32.dll', 'dword', 'GetLogicalDrives')
- Local $td = DllStructCreate('dword;dword;int')
- Local $hDevice, $aRt, $nDrive, $nMax, $sInfo = ''
- For $ii = 0 To 25
- If Not BitAND(BitShift($iMask[0], $ii), 1) Then ContinueLoop
- $aRt = DllCall('kernel32.dll', 'hwnd', 'CreateFile', 'str', '\\.\' & Chr(65 + $ii) & ':', 'dword', 0, 'dword', 0, 'ptr', 0, 'dword', 3, 'dword', 128, 'ptr', 0)
- $hDevice = $aRt[0]
- DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'hwnd', $hDevice, 'dword', 0x2D1080, 'ptr', 0, 'dword', 0, 'ptr', DllStructGetPtr($td), 'dword', DllStructGetSize($td), 'dword*', 0, 'ptr', 0)
- DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $hDevice)
- $nDrive = DllStructGetData($td, 2)
- If $nMax < $nDrive Then $nMax = $nDrive
- $sInfo &= Chr(65 + $ii) & ': 硬盘 ' & $nDrive & ', 分区 ' & DllStructGetData($td, 3) & @CRLF
- Next
- GUICtrlSetData($iLb, '当前接入硬盘数量:' & $nMax + 1)
- GUICtrlSetData($iEdit, $sInfo)
- GUICtrlSetState($iLb, 256)
- EndFunc ;==>_DeviceInfo
- Func _WM_DEVICECHANGE($hWnd, $Msg, $wParam, $lParam)
- Switch $wParam
- Case 0x8000, 0x8004
- _DeviceInfo()
- EndSwitch
- EndFunc ;==>_WM_DEVICECHANGE
复制代码 |