找回密码
 加入
搜索
查看: 5384|回复: 5

[GUI管理] au3拖动bug怎样避免?【已解决】

  [复制链接]
发表于 2011-3-12 20:49:31 | 显示全部楼层 |阅读模式
本帖最后由 zhangla 于 2011-3-12 23:55 编辑

今天要用到au3的input,想实现拖动文件或文件夹到input功能,结构出现了这样的情况


有没有简单点的解决办法?
示例用的GUICtrlCreateInput 帮助里的例子
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $file, $btn, $msg
   
    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, $GUI_DROPACCEPTED)
    GUICtrlCreateInput("", 10, 35, 300, 20)     ; will not accept drag&drop files
    $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", GUICtrlRead($file))
EndFunc   ;==>Example

本帖子中包含更多资源

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

×
发表于 2011-3-12 23:12:54 | 显示全部楼层
本帖最后由 yhxhappy 于 2011-3-12 23:43 编辑

LZ的意思是不是想用新拖动的文件名替换旧的,而不是连起来啊?如果是这样用事件模式要好些

#include <GUIConstantsEx.au3>


Opt("GUIOnEventMode", 1)

Local $file, $btn, $msg
    
GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI")
        GUISetOnEvent($GUI_EVENT_DROPPED, "_GUI")

$file = GUICtrlCreateInput("", 10, 5, 300, 20)
        GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateInput("", 10, 35, 300, 20)     ; will not accept drag&drop files
$btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)
        GUICtrlSetOnEvent(-1, "_GUI")

GUISetState()

While 1
        Sleep(10)
WEnd        


Func _GUI()
        Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE, $btn
                MsgBox(4096, "drag drop file", GUICtrlRead($file))
                Exit
        Case $GUI_EVENT_DROPPED
                        GUICtrlSetData($file, @GUI_DRAGFILE)
        EndSwitch
EndFunc
        

评分

参与人数 1金钱 +22 贡献 +2 收起 理由
lynfr8 + 22 + 2

查看全部评分

发表于 2011-3-12 23:37:05 | 显示全部楼层
消息循环模式同样可以做到。
思路:
1、通过正则来检测输入框是否含2个路径
2、若路径不等于1则获取最后拖曳的路径并填入输入框
#include <GUIConstantsEx.au3>
Example()
Func Example()
    Local $file, $btn, $msg
    $Form1=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, $GUI_DROPACCEPTED)
    GUICtrlCreateInput("", 10, 35, 300, 20)     ; will not accept drag&drop files
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ExitLoop
                        Case $GUI_EVENT_DROPPED
                                If StringRegExp(GUICtrlRead($file),'.*:.*:',0) = 1 Then GUICtrlSetData($file,ControlCommand($Form1, '', $file, 'GetSelected', ''))
        EndSelect
    WEnd

    MsgBox(4096, "drag drop file", GUICtrlRead($file))
EndFunc   ;==>Example
 楼主| 发表于 2011-3-12 23:42:43 | 显示全部楼层
本帖最后由 zhangla 于 2011-3-12 23:44 编辑

回复 2# yhxhappy


    谢谢您的回答,没有好的解决办法也只能这样了。
实际上我说的那种模式只要不去点击input,还是可以用后托的替换input中的内容的。
我想也有解决方法,就是点击input后在离开input时让它失去焦点应该可以解决,空了试试看。
 楼主| 发表于 2011-3-12 23:48:45 | 显示全部楼层
回复 3# lynfr8

lynfr8 的方法也是好方法,谢谢了……
呵呵。
题外话:我的贡献还为0,那天空了我也贡献点自己写的代码。
发表于 2011-3-13 00:33:09 | 显示全部楼层
回复  yhxhappy


    谢谢您的回答,没有好的解决办法也只能这样了。
实际上我说的那种模式只要不去点 ...
zhangla 发表于 2011-3-12 23:42


点击input后在离开input时让它失去焦点并不可以解决路径重叠问题
貌似控件会记忆上一次焦点位置
即使失去焦点下一次拖曳路径依然会出现你帖子提到的问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-13 05:20 , Processed in 0.087665 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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