找回密码
 加入
搜索
查看: 6590|回复: 9

[GUI管理] 【已解决】文件拖放时,如何清空Inputbox里原本的内容,谢谢!

  [复制链接]
发表于 2014-9-24 17:12:19 | 显示全部楼层 |阅读模式
本帖最后由 touch_xu 于 2014-9-24 18:27 编辑


#include <GUIConstants.au3>

GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateInput("请把文件拖放至此", 10, 5, 300, 20)

GUICtrlSetState(-1, BitOR($GUI_DROPACCEPTED, $GUI_DISABLE))

$btn = GUICtrlCreateButton("OK", 40, 75, 60, 20)

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
                Case $msg = $btn
                        ExitLoop
                        
        EndSelect
WEnd

MsgBox(4096, "drag drop file", @GUI_DragFile)

本帖子中包含更多资源

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

×
发表于 2014-9-24 17:54:28 | 显示全部楼层
回复 1# touch_xu
Case $msg = $GUI_EVENT_DROPPED
        GUICtrlSetData($file, '')
        GUICtrlSetData($file,@GUI_DragFile )
 楼主| 发表于 2014-9-24 18:26:40 | 显示全部楼层
回复 2# user3000


    感谢user3000 ,测试通过,正解,谢谢!
发表于 2014-9-24 19:06:54 | 显示全部楼层
其实 你可以去看看帮助文件夹里的源码

;请参考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, $Input1, $hInput1, $hDll, $pDll, $hProc

OnAutoItExitRegister('OnAutoItExit')

; Create GUI
$hForm = GUICreate('文本框接受拖拽文件得到路径', 400, 200)
$Input1 = GUICtrlCreateInput("Input1", 64, 64, 321, 21)
$hInput1 = GUICtrlGetHandle($Input1)


; Register label window proc
$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLong($hInput1, $GWL_WNDPROC, $pDll)
_WinAPI_DragAcceptFiles($hInput1, True)
GUISetState()

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case -3
                        ExitLoop
                        
        EndSwitch
WEnd

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
        Local $str
        Switch $iMsg
                Case $WM_DROPFILES

                        Local $FileList = _WinAPI_DragQueryFileEx($wParam)

                        If IsArray($FileList) Then
                                $str = ""
                                For $i = 1 To $FileList[0]
                                        $str &= $FileList[$i] & @CRLF
                                Next
                                GUICtrlSetData($Input1, $str)
                        EndIf
                        _WinAPI_DragFinish($wParam)
                        Return 0
        EndSwitch
        Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func OnAutoItExit()
        _WinAPI_SetWindowLong($hInput1, $GWL_WNDPROC, $hProc)
        DllCallbackFree($hDll)
EndFunc   ;==>OnAutoItExit
 楼主| 发表于 2014-9-24 19:53:07 | 显示全部楼层
回复 4# veket_linux


    感谢,不过这个似乎复杂点,仍然感谢!
 楼主| 发表于 2014-9-24 19:53:50 | 显示全部楼层
回复 2# user3000


    感谢,如果是两个input如何区分ID呢,谢谢!
 楼主| 发表于 2014-9-24 20:00:34 | 显示全部楼层
回复  user3000


    感谢,如果是两个input如何区分ID呢,谢谢!
touch_xu 发表于 2014-9-24 19:53



    @GUI_DRAGID,却不知道如何使用。
 楼主| 发表于 2014-9-24 20:07:18 | 显示全部楼层
本帖最后由 touch_xu 于 2014-9-24 22:40 编辑
@GUI_DRAGID,却不知道如何使用。
touch_xu 发表于 2014-9-24 20:00


已经彻底解决了, 谢谢!

代码如下:

但是如何在 ONEVENT 模式下捕获呢?
#include <GUIConstants.au3>

GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateInput("请把文件拖放至此", 10, 5, 300, 20)

GUICtrlSetState(-1, BitOR($GUI_DROPACCEPTED, $GUI_DISABLE))

$btn = GUICtrlCreateButton("OK", 40, 75, 60, 20)

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
                Case $msg = $btn
                        ExitLoop
                Case $msg = $GUI_EVENT_DROPPED
                               GUICtrlSetData($file, '')
                        GUICtrlSetData($file,@GUI_DragFile )
                        
        EndSelect
WEnd

MsgBox(4096, "drag drop file", @GUI_DragFile)
 楼主| 发表于 2014-9-24 22:50:56 | 显示全部楼层
已经彻底解决了, 谢谢!

代码如下:

但是如何在 ONEVENT 模式下如何捕获呢?
touch_xu 发表于 2014-9-24 20:07



    这几天不知道怎么了,试了好久都不行,总是在发完求助之后就找到方法了,已经OK了,谢谢名位.
发表于 2014-11-26 12:39:11 | 显示全部楼层
回复 9# touch_xu


    兄台如何在事件模式下解决的,求教!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 16:35 , Processed in 0.088052 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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