#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1);OnEvent模式
Global Const $WM_DEVICECHANGE = 0x0219
Global Const $DBT_DEVICEARRIVAL = 0x8000
Global Const $DBT_DEVICEREMOVECOMPLETE = 0x8004
Local $menu_A[5], $U[5]
GUIRegisterMsg($WM_DEVICECHANGE, '_DEVICECHANGE')
GUICreate("检测")
$menu = GUICtrlCreateMenu("文件")
CreatMenu()
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
While 1
Sleep(10)
WEnd
Func _DEVICECHANGE($hWnd, $Msg, $wParam, $lParam)
Switch $wParam
Case $DBT_DEVICEARRIVAL, $DBT_DEVICEREMOVECOMPLETE
For $i = 1 To UBound($menu_A)
GUICtrlDelete($menu_A[$i - 1])
Next
CreatMenu()
EndSwitch
EndFunc ;==>_DEVICECHANGE
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $menu_A[0]
ShellExecute($U[0])
Case $menu_A[1]
ShellExecute($U[1])
Case $menu_A[2]
ShellExecute($U[2])
Case $menu_A[3]
ShellExecute($U[3])
Case $menu_A[4]
ShellExecute($U[4])
EndSwitch
EndFunc ;==>gui
Func CreatMenu()
$Drive = DriveGetDrive("REMOVABLE")
If IsArray($Drive) Then
For $i = 1 To $Drive[0]
$menu_A[$i - 1] = GUICtrlCreateMenuItem("打开" & StringUpper($Drive[$i]) & "\", $menu)
$U[$i - 1] = $Drive[$i]
GUICtrlSetOnEvent($menu_A[$i - 1], "gui")
Next
EndIf
EndFunc ;==>CreatMenu
|