找回密码
 加入
搜索
查看: 1802|回复: 3

[系统综合] 请教 输入框如果支持鼠标拖拉文件(已解决)

[复制链接]
发表于 2017-7-2 09:36:30 | 显示全部楼层 |阅读模式
本帖最后由 baosheng00 于 2017-7-2 11:45 编辑

想在输入框使用鼠标拉文件或文件夹,输入框自动获取鼠标拖拉文件的路径。百度查找,论坛也找过没有相关的信息,在此求助!




以下代码看怎么改才支持,
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试", 416, 233, 287, 153)
$Input1 = GUICtrlCreateInput("", 56, 40, 217, 21)
$Button1 = GUICtrlCreateButton("选择", 296, 40, 75, 25)
$Button2 = GUICtrlCreateButton("确定", 56, 160, 107, 25)
$Button3 = GUICtrlCreateButton("取消", 248, 160, 99, 25)
$Label1 = GUICtrlCreateLabel("Label1", 56, 88, 292, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        
                Case $Button1        
                        liulang()
                Case $Button2
                        $1=GUICtrlRead($Input1)
                        GUICtrlSetData($Label1,$1)
                Case $Button3        
                        GUICtrlSetData($Label1,"")
        EndSwitch
WEnd

    Func liulang();浏览按钮,
       $ll=FileSelectFolder("浏览","")            
        If FileExists($ll) Then
            GUICtrlSetData($Input1,$ll)
                EndIf
    EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-7-2 10:14:12 | 显示全部楼层
回复 1# baosheng00

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试", 416, 233, 287, 153, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_ACCEPTFILES) ;接受拖放文件
$Input1 = GUICtrlCreateInput("", 56, 40, 217, 21)
GUICtrlSetState(-1, $GUI_ACCEPTFILES) ;接受拖放文件
$Button1 = GUICtrlCreateButton("选择", 296, 40, 75, 25)
$Button2 = GUICtrlCreateButton("确定", 56, 160, 107, 25)
$Button3 = GUICtrlCreateButton("取消", 248, 160, 99, 25)
$Label1 = GUICtrlCreateLabel("Label1", 56, 88, 292, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        liulang()
                Case $Button2
                        $1=GUICtrlRead($Input1)
                        GUICtrlSetData($Label1,$1)
                Case $Button3
                        GUICtrlSetData($Label1,"")
        EndSwitch
WEnd

    Func liulang();浏览按钮,
       $ll=FileSelectFolder("浏览","")
        If FileExists($ll) Then
            GUICtrlSetData($Input1,$ll)
                EndIf
    EndFunc
 楼主| 发表于 2017-7-2 11:46:34 | 显示全部楼层
回复 2# chzj589


    谢谢你,已经解决了我的问题
发表于 2017-7-6 20:40:48 | 显示全部楼层


;修改自au3自带例子改
;autoit3\Examples\WinAPIEx\_WinAPI_DragAcceptFiles.au3

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $WM_DROPFILES = 0x0233

Global $hForm, $Msg, $Check, $Label, $hLabel, $hDll, $pDll, $hProc
Global $Input1, $hInput1
OnAutoItExitRegister('OnAutoItExit')

; Create GUI
$hForm = GUICreate('MyGUI', 400, 400)
;$Check = GUICtrlCreateCheckbox('Enable Drag && Drop', 10, 370, 120, 19)
;$Label = GUICtrlCreateLabel('', 100, 100, 200, 200)
;$hLabel = GUICtrlGetHandle($Label)
$input1 = GUICtrlCreateInput("", 20, 50, 300, 30)
$hInput1 = GUICtrlGetHandle($Input1)
;GUICtrlSetBkColor(-1, 0xD3D8EF)
;GUICtrlCreateLabel('Drop here', 175, 193, 50, 14)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

; Register label window proc
$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
;$hProc = _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $pDll)
$hProc = _WinAPI_SetWindowLong($hInput1, $GWL_WNDPROC, $pDll)
_WinAPI_DragAcceptFiles($hInput1, True)
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)
                                        GUICtrlSetData($Input1, $filelist[$i])
                                        ExitLoop
                                Next
                        EndIf
                        _WinAPI_DragFinish($wParam)
                        Return 0
        EndSwitch
        Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func OnAutoItExit()
        ;_WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $hProc)
        _WinAPI_SetWindowLong($hInput1, $GWL_WNDPROC, $hProc)
        DllCallbackFree($hDll)
EndFunc   ;==>OnAutoItExit

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 07:39 , Processed in 0.074396 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表