找回密码
 加入
搜索
查看: 3371|回复: 10

[AU3基础] 拖放文件 到 Edit 显示的问题【以解决】

  [复制链接]
发表于 2010-7-2 14:59:02 | 显示全部楼层 |阅读模式
本帖最后由 woeiwoei 于 2010-7-2 15:30 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include<array.au3>
$help= TrayCreateItem("帮助")
TrayItemSetOnEvent(-1, "_help")
$guanyu= TrayCreateItem("关于")
TrayItemSetOnEvent(-1, "_GY")
$_exit = TrayCreateItem("退出")
TrayItemSetOnEvent(-1, "ExitEvent")
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode", 15)
Opt("GUIOnEventMode", 1)
;Dim $Dll
;FileInstall("SkinCrafterDll.dll",@WindowsDir & "\temp\SkinCrafterDll.dll","1")
;FileInstall("BlackPearl.skf",@WindowsDir & "\temp\BlackPearl.skf","1")
$Form1 = GUICreate("Form1", 420, 310, 321, 135,$GUI_DROPACCEPTED,$WS_EX_ACCEPTFILES)
;_SkinGUI(@WindowsDir & "\temp\SkinCrafterDll.dll" ,@WindowsDir & "\temp\BlackPearl.skf", $Form1)
$Edit=GUICtrlCreateEdit("", 8, 64, 401, 145)

$MenuItem1 = GUICtrlCreateMenu ("操作说明")
$MenuItem1_1 = GUICtrlCreateMenuItem("帮助",$MenuItem1)
GUICtrlSetOnEvent (-1,"_help")
$MenuItem1_2 = GUICtrlCreateMenuItem("关于",$MenuItem1)
GUICtrlSetOnEvent (-1,"_GY")
$MenuItem1_3 = GUICtrlCreateMenuItem("退出",$MenuItem1)
GUICtrlSetOnEvent (-1,"ExitEvent")
$Button1 = GUICtrlCreateButton("保存", 120, 224, 73, 25)
$Button2 = GUICtrlCreateButton("取消", 224, 224, 73, 25)
GUISetState(@SW_SHOW)
;$curFile = $BackupFilePath
;$fileresult = _ReadFileInfo($curfile) 
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_DROPPED, "GUI_Drop")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
               Case $GUI_EVENT_CLOSE
                Exit
               Case $Button2
                 Exit
        EndSwitch
WEnd

Func GUI_Drop()
$file=@GUI_DragFile
GUICtrlSetData($Edit, $file,@GUI_DragFile)
EndFunc

Func _GY()
 MsgBox(0,"","TEST")
EndFunc ;----关于

Func _help()

MsgBox(0,"","帮助")
EndFunc

Func ExitEvent()
Exit 0
EndFunc
可以拖放文件到窗口上了。但是 获取不到 被拖放文件的 名字 到 EDIT 。。
我想拖放 一个文件 到窗口上的时候 文件的名字 就被 显示到 编辑框里。。但是不知道那里出错了。。
还有点小问题 GUIOnEventMode 这个模式。。。我点 下拉菜单按钮 的 退出 可以退出程序。但是我点 窗口中的取消 却不能退出。
如果是 GUIOnEventMode =0 的时候  则反之。。晕晕。。
谁能帮帮我呢。。

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-7-2 15:22:20 | 显示全部楼层
已改好~ 另外,对于支持拖放的窗口最好设置顶层窗口,免得拖了找不到地方放,已加入相关代码
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include<array.au3>
$help = TrayCreateItem("帮助")
TrayItemSetOnEvent(-1, "_help")
$guanyu = TrayCreateItem("关于")
TrayItemSetOnEvent(-1, "_GY")
$_exit = TrayCreateItem("退出")
TrayItemSetOnEvent(-1, "ExitEvent")
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 15)
Opt("GUIOnEventMode", 1)
;Dim $Dll
;FileInstall("SkinCrafterDll.dll",@WindowsDir & "\temp\SkinCrafterDll.dll","1")
;FileInstall("BlackPearl.skf",@WindowsDir & "\temp\BlackPearl.skf","1")

$Form1 = GUICreate("Form1", 420, 310, 321, 135, $GUI_DROPACCEPTED, $WS_EX_ACCEPTFILES)
;_SkinGUI(@WindowsDir & "\temp\SkinCrafterDll.dll" ,@WindowsDir & "\temp\BlackPearl.skf", $Form1)
$Edit = GUICtrlCreateEdit("", 8, 64, 401, 145)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "GUI_Drop")

$MenuItem1 = GUICtrlCreateMenu("操作说明")
$MenuItem1_1 = GUICtrlCreateMenuItem("帮助", $MenuItem1)
GUICtrlSetOnEvent(-1, "_help")
$MenuItem1_2 = GUICtrlCreateMenuItem("关于", $MenuItem1)
GUICtrlSetOnEvent(-1, "_GY")
$MenuItem1_3 = GUICtrlCreateMenuItem("退出", $MenuItem1)
GUICtrlSetOnEvent(-1, "ExitEvent")
$Button1 = GUICtrlCreateButton("保存", 120, 224, 73, 25)
$Button2 = GUICtrlCreateButton("取消", 224, 224, 73, 25)
GUICtrlSetOnEvent(-1, "ExitEvent")

GUISetState()
WinSetOnTop($Form1, '', 1)
;$curFile = $BackupFilePath
;$fileresult = _ReadFileInfo($curfile)
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_DROPPED, "GUI_Drop")

While 1
        Sleep(10)
WEnd

Func GUI_Drop()
        $file = @GUI_DragFile
        GUICtrlSetData($Edit, $file, @GUI_DragFile)
EndFunc   ;==>GUI_Drop

Func _GY()
        MsgBox(0, "", "TEST")
EndFunc   ;==>_GY

Func _help()
        MsgBox(0, "", "帮助")
EndFunc   ;==>_help

Func ExitEvent()
        Exit 0
EndFunc   ;==>ExitEvent

评分

参与人数 1金钱 +9 收起 理由
lynfr8 + 9

查看全部评分

 楼主| 发表于 2010-7-2 15:28:48 | 显示全部楼层
本帖最后由 woeiwoei 于 2010-7-2 15:30 编辑

afan 大大 咋感谢你。。每次都是你帮我~~~
你是个神奇的人物!!!
发表于 2010-7-2 15:34:37 | 显示全部楼层
本帖最后由 afan 于 2010-7-2 15:36 编辑

回复 3# woeiwoei


    你是美女嘛~ 不帮你帮谁~ 我诶薇我诶薇...
 楼主| 发表于 2010-7-2 15:36:46 | 显示全部楼层
afan 大大。。能告诉我那错了吗?我看到你就加了个置顶 然后去掉了 while 里的 case 其他的没变啊。。
我晕晕的。。
发表于 2010-7-2 15:38:45 | 显示全部楼层
$Edit = GUICtrlCreateEdit("", 8, 64, 401, 145)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "GUI_Drop")

...
$Button2 = GUICtrlCreateButton("取消", 224, 224, 73, 25)
GUICtrlSetOnEvent(-1, "ExitEvent")
 楼主| 发表于 2010-7-2 15:50:25 | 显示全部楼层
afan 发表于 2010-7-2 15:38



    哦。。原来如此。。afan大大。如果只需要获取 文件名 而不需要 路径
用@GUI_DragID 或者 @GUI_DropID 为啥只显示个 3呢?
发表于 2010-7-2 15:55:31 | 显示全部楼层
Func GUI_Drop()
        $file = StringRegExpReplace(@GUI_DragFile, '.+\\', '')
        GUICtrlSetData($Edit, $file, ' ')
EndFunc   ;==>GUI_Drop
 楼主| 发表于 2010-7-2 15:55:38 | 显示全部楼层

额。。总 宏说明 和直接查的 不一样~

本帖子中包含更多资源

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

×
 楼主| 发表于 2010-7-2 15:57:41 | 显示全部楼层
afan 大大 我都不好意思麻烦你了。。。
非常感谢。我会认真学习的~~争取 少麻烦你~~
发表于 2010-7-2 16:00:13 | 显示全部楼层
不用那么客气吧~ 大家都是互相学习的~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-3 17:15 , Processed in 0.087652 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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