请问一下文件拖放,如何删除输入框以存在的路径(已经解决)
本帖最后由 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内容为
u1=D:\disk1
u2=D:\disk2
都支持拖放文件,第一个输入框$Input1拖放文件会删除输入框的内容,拖放第二个输入框$Input2,总是不会删除路径(拖放的是D:\桌面\收藏夹.EXE),造成路径不正常,如下图,请问一下如何解决! (论坛找过,只有一个输入框的,还没有找到两个的!)
#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
$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 + 1] = [$aRet]
For $i = 0 To $aRet - 1
$aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
$iSize = $aRet + 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 回复 2# ura
这个已经有找过了看过,拖放一个文件就正常,我这个是两个拖放文件位置,就不一样了 回复 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
回复 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 回复baosheng00
這樣應該可以了
kk_lee69 发表于 2017-7-26 22:48 http://www.autoitx.com/images/common/back.gif
如果有很多输入框那这样就繁琐了,20-27行其实只需一行即可
GUICtrlSetData(@GUI_DROPID, @GUI_DRAGFILE) 回复 6# afan
對只要一行我想多了@@ 仅处理 GUI_EVENT_DROPPED也是可以, 不过在消息中可以处理其他的事情 回复 7# kk_lee69
没记错的话。@ctrlid之类的应该是事件模式才能用的吧?你这代码应该不能运行才对 回复 9# yamakawa
可不可以用 試一下我的代碼不就知道 本帖最后由 yamakawa 于 2017-7-27 13:31 编辑
回复 10# kk_lee69
win10 X64表示拖进去文件无反应
回复 11# yamakawa
這樣看來 WIN10 WIN7還是有差別的 文件拖动,学习到了。 话说我的Win10 X64可以呀。
页:
[1]