#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$DBT_DEVICEARRIVAL = 0x8000
$DBT_DEVICEREMOVECOMPLETE = 0x8004
$DBT_DEVTYP_VOLUME = 0x00000002
$DEV_BROADCAST_HDR = "DWORD size;DWORD devicetype;DWORD reserved"
$DEV_BROADCAST_VOLUME = "DWORD size;DWORD devicetype;DWORD reserved;DWORD unitmask;WORD flags"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 294, 187, 192, 124)
$Edit1 = GUICtrlCreateCombo("", 16, 16, 265, 25)
GUICtrlSetFont(-1, 10, 400, 0, 'Arial')
$Button1 = GUICtrlCreateButton("获取U盘", 152, 152, 75, 25)
move()
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_DEVICECHANGE, "WM_DEVICECHANGE")
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
move()
EndSwitch
WEnd
Func WM_DEVICECHANGE($hWnd, $MsgID, $WParam, $LParam)
Switch $WParam
Case $DBT_DEVICEARRIVAL, $DBT_DEVICEREMOVECOMPLETE
$dbhdr = DllStructCreate($DEV_BROADCAST_HDR, $LParam)
$devicetype = DllStructGetData($dbhdr, "devicetype")
Switch $devicetype
Case $DBT_DEVTYP_VOLUME
$dbv = DllStructCreate($DEV_BROADCAST_VOLUME, $LParam)
$unitmask = DllStructGetData($dbv, "unitmask")
For $i = 0 To 25
If BitAND(BitShift(1, -$i), $unitmask) <> 0 Then move()
Next
EndSwitch
EndSwitch
EndFunc ;==>WM_DEVICECHANGE
Func move()
GUICtrlSetData($Edit1, "", "")
GUICtrlSetColor($Edit1, 0x000000)
$zi = "已连接的设备盘符为 ==> "
$drive = DriveGetDrive("REMOVABLE");获取可移动驱动器
If Not @error Then
Local $daxie = ""
For $i = 1 To $drive[0]
$daxie &= StringUpper($drive[$i]) & Chr(32);将小写盘符转换大写
Next
GUICtrlSetData($Edit1, $zi & $daxie, $zi & $daxie);修改指定控件的数据,$Edit2是那个输入框
ControlCommand($Form1, "", 'ComboBox1', "SetCurrentSelection", 0)
GUICtrlSetColor($Edit1, 0x0000FF)
Else
MsgBox(16, "警告!", "未发现有U盘。", "", $Form1);显示一个简单的对话框
EndIf
EndFunc ;==>move