找回密码
 加入
搜索
查看: 2181|回复: 13

[网络通信] 请问一下文件拖放,如何删除输入框以存在的路径(已经解决)

 火.. [复制链接]
发表于 2017-7-26 17:32:43 | 显示全部楼层 |阅读模式
本帖最后由 baosheng00 于 2017-7-26 23:01 编辑

代码如下
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$U1 = IniRead(@ScriptDir&"\2.INI", "setup", "u1", "")        
$U2 = IniRead(@ScriptDir&"\2.INI", "setup", "u2", "")        

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=d:\桌面\form1.kxf
$Form1_1 = GUICreate("Form1", 449, 278, 389, 215,BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_ACCEPTFILES)
$Input1 = GUICtrlCreateInput($U1, 56, 24, 265, 21)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$Input2 = GUICtrlCreateInput($U2, 56, 64, 265, 21)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("", 56, 112, 354, 81)
$Button1 = GUICtrlCreateButton("浏览1", 336, 24, 75, 25)
$Button2 = GUICtrlCreateButton("浏览2", 336, 64, 75, 25)
$Button3 = GUICtrlCreateButton("确定", 72, 224, 99, 33)
$Button4 = GUICtrlCreateButton("取消", 272, 224, 99, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        
                Case $Button1        
                        liulang1()
                Case $Button2        
                        liulang2()                                                
                Case $Button3
                        $1=GUICtrlRead($Input1)
                                                $2=GUICtrlRead($Input2)
                        GUICtrlSetData($Label1,$1&@CRLF&$2)
                Case $Button4        
                        GUICtrlSetData($Input1,"")
                                                GUICtrlSetData($Input2,"")
                                                GUICtrlSetData($Label1,"")
        EndSwitch
WEnd


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

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






 
读取配置文件2.ini的内容,2.ini内容为
[setup]
u1=D:\disk1
u2=D:\disk2
都支持拖放文件,第一个输入框$Input1拖放文件会删除输入框的内容,拖放第二个输入框$Input2,总是不会删除路径(拖放的是D:\桌面\收藏夹.EXE),造成路径不正常,如下图,请问一下如何解决!   (论坛找过,只有一个输入框的,还没有找到两个的!)

本帖子中包含更多资源

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

×
发表于 2017-7-26 18:55:11 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $aDrop_List

$Gui1 = GUICreate("Drag File", 400, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
$Edit1 = GUICtrlCreateEdit('Drag and drop your files here', 0, 0, 400, 200)
GUICtrlSetState($Edit1, $GUI_DROPACCEPTED)
GUISetState()
GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')

While True
        Switch GUIGetMsg()
                Case -3
                        Exit

                Case $GUI_EVENT_DROPPED
                        GUICtrlSetData($Edit1, "")
                        For $i = 1 To $aDrop_List[0]
                                $old = GUICtrlRead($Edit1)
                                $new = $old & $aDrop_List[$i] & @CRLF
                                GUICtrlSetData($Edit1, $new)
                        Next                

        EndSwitch
WEnd

Func WM_DROPFILES($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $lParam
    Local $iSize, $pFileName
    Local $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 0)
   
        Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]]

    For $i = 0 To $aRet[0] - 1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $iSize = $aRet[0] + 1
        $pFileName = DllStructCreate("wchar[" & $iSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $iSize)
        $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next

EndFunc
 楼主| 发表于 2017-7-26 21:40:23 | 显示全部楼层
回复 2# ura


    这个已经有找过了看过,拖放一个文件就正常,我这个是两个拖放文件位置,就不一样了
发表于 2017-7-26 22:48:03 | 显示全部楼层
回复 1# baosheng00

這樣應該可以了

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Gui1 = GUICreate("Drag File", 400, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
$Edit1 = GUICtrlCreateInput('Drag and drop your files here', 0, 0, 200, 50)
GUICtrlSetState($Edit1, $GUI_DROPACCEPTED)
$Edit2 = GUICtrlCreateInput('Drag and drop your files here', 0, 100, 200, 50)
GUICtrlSetState($Edit2, $GUI_DROPACCEPTED)

GUISetState()


While True
        Switch GUIGetMsg()
                Case -3
                        Exit

                Case $GUI_EVENT_DROPPED
                                        If @GUI_DROPID=$Edit1 Then 
                                                GUICtrlSetData($Edit1,"")
                                                GUICtrlSetData($Edit1,@GUI_DRAGFILE)
                                        EndIf        
                                        If @GUI_DROPID=$Edit2 Then 
                                                GUICtrlSetData($Edit2,"")
                                                GUICtrlSetData($Edit2,@GUI_DRAGFILE)
                                        EndIf        


        EndSwitch
WEnd
 楼主| 发表于 2017-7-26 23:00:50 | 显示全部楼层
回复 4# kk_lee69


    谢谢已经解决

就这个


                Case $GUI_EVENT_DROPPED


                                        If @GUI_DROPID=$Edit1 Then


                                                GUICtrlSetData($Edit1,"")


                                                GUICtrlSetData($Edit1,@GUI_DRAGFILE)


                                        EndIf   


                                        If @GUI_DROPID=$Edit2 Then


                                                GUICtrlSetData($Edit2,"")


                                                GUICtrlSetData($Edit2,@GUI_DRAGFILE)


                                        EndIf
发表于 2017-7-26 23:04:55 | 显示全部楼层
回复  baosheng00

這樣應該可以了
kk_lee69 发表于 2017-7-26 22:48



    如果有很多输入框那这样就繁琐了,20-27行其实只需一行即可
GUICtrlSetData(@GUI_DROPID, @GUI_DRAGFILE)
发表于 2017-7-26 23:06:25 | 显示全部楼层
回复 6# afan

對只要一行  我想多了@@
发表于 2017-7-27 07:18:18 | 显示全部楼层
仅处理 GUI_EVENT_DROPPED也是可以, 不过在消息中可以处理其他的事情
发表于 2017-7-27 12:14:27 | 显示全部楼层
回复 7# kk_lee69


    没记错的话。@ctrlid之类的应该是事件模式才能用的吧?你这代码应该不能运行才对
发表于 2017-7-27 13:14:54 | 显示全部楼层
回复 9# yamakawa

可不可以用 試一下我的代碼  不就知道
发表于 2017-7-27 13:21:19 | 显示全部楼层
本帖最后由 yamakawa 于 2017-7-27 13:31 编辑

回复 10# kk_lee69


    win10 X64表示拖进去文件无反应

本帖子中包含更多资源

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

×
发表于 2017-7-27 14:00:28 | 显示全部楼层
回复 11# yamakawa

這樣看來 WIN10   WIN7  還是有差別的
发表于 2017-7-30 20:00:42 | 显示全部楼层
文件拖动,学习到了。
发表于 2017-7-30 20:58:34 | 显示全部楼层
话说我的Win10 X64可以呀。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

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

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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