检索拖放操作成功后的文件名称.
#Include <WinAPIEx.au3>
_WinAPI_DragQueryFileEx ( $hDrop [, $iFlag] )
$hDrop | 描述被拖动文件的结构句柄. 此参数被传递给 WM_DROPFILES 消息中的 WPARAM 参数. |
$iFlag | [可选参数] 指定是否返回文件、文件夹或两者同时返回, 有效值为: 0 - 返回文件和文件夹. (默认) 1 - 返回文件. 2 - 返回文件夹. |
成功: | 返回拖放成功后的文件名数组. 元素 [0] 包含文件名的数量. |
如果没有满足条件($iFlag)的文件, 函数将失败. | |
失败: | 返回 0,并设置@error标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $hForm, $Msg, $Check, $Label, $hLabel, $hDll, $pDll, $hProc
OnAutoItExitRegister('OnAutoItExit')
; 创建 GUI
$hForm = GUICreate('MyGUI', 400, 400)
$Check = GUICtrlCreateCheckbox('Enable Drag && Drop', 10, 370, 120, 19)
$Label = GUICtrlCreateLabel('', 100, 100, 200, 200)
$hLabel = GUICtrlGetHandle($Label)
GUICtrlSetBkColor(-1, 0xD3D8EF)
GUICtrlCreateLabel('Drop here', 175, 193, 50, 14)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
; Allow WM_DROPFILES to be received from lower privileged processes (Windows Vista or later)
#cs
If IsAdmin() Then
_WinAPI_ChangeWindowMessageFilterEx($hLabel, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($hLabel, $WM_DROPFILES, $MSGFLT_ALLOW)
EndIf
#ce
; 注册标签窗口过程
$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLongEx($hLabel, $GWL_WNDPROC, $pDll)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
ExitLoop
Case $Check
_WinAPI_DragAcceptFiles($hLabel, GUICtrlRead($Check) = $GUI_CHECKED)
EndSwitch
WEnd
Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_DROPFILES
Local $FileList = _WinAPI_DragQueryFileEx($wParam)
If IsArray($FileList) Then
ConsoleWrite('--------------------------------------------------' & @CR)
For $i = 1 To $FileList[0]
ConsoleWrite($FileList[$i] & @CR)
Next
EndIf
_WinAPI_DragFinish($wParam)
Return 0
EndSwitch
Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_WinProc
Func OnAutoItExit()
_WinAPI_SetWindowLongEx($hLabel, $GWL_WNDPROC, $hProc)
DllCallbackFree($hDll)
EndFunc ;==>OnAutoItExit