找回密码
 加入
搜索
查看: 6694|回复: 14

关于listview拖放问题

[复制链接]
发表于 2009-4-26 22:38:09 | 显示全部楼层 |阅读模式
本帖最后由 jchang 于 2009-4-28 14:42 编辑

根据UICtrlCreateListView的帮助文件的例子,想增加如下功能:
把文件拖放到listview后,item2|col22|col23都显示出文件或者文件夹的路径,请问应该如何实现呢?

原example的代码如下:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
        Local $listview, $button, $item1, $item2, $item3, $input1, $msg
       
        GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
        GUISetBkColor(0x00E0FFFF)  ; will change background color

        $listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
        $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
        $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
        $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
        $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
        $input1 = GUICtrlCreateInput("", 20, 200, 150)
        GUICtrlSetState(-1, $GUI_DROPACCEPTED)   ; to allow drag and dropping
        GUISetState()
        GUICtrlSetData($item2, "ITEM1")
        GUICtrlSetData($item3, "||COL33")
        GUICtrlDelete($item1)

        Do
                $msg = GUIGetMsg()
               
                Select
                        Case $msg = $button
                                MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
                        Case $msg = $listview
                                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
                EndSelect
        Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
发表于 2009-4-26 23:04:07 | 显示全部楼层
本帖最后由 131738 于 2009-4-27 18:49 编辑

//////////////////////////////////////
发表于 2009-4-27 09:16:58 | 显示全部楼层
[au3]#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>

Global Const $WM_DROPFILES = 0x0233

Global $aDroppedFiles[1]

GUICreate("支持拖放文件的ListView", 500, 400, -1, -1, -1, $WS_EX_ACCEPTFILES+$WS_EX_TOPMOST)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

GUICtrlCreateLabel("把文件拖放到ListView看看", 60, 20)

$ListView = GUICtrlCreateListView("Col1|Col2", 50, 50, 400, 300, -1, $WS_EX_CLIENTEDGE)
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetState()

While 1
    $Msg = GUIGetMsg()
   
    Switch $Msg
        Case -3
            Exit
        Case $GUI_EVENT_DROPPED
            For $i = 1 To UBound($aDroppedFiles)-1
                                $file=StringSplit($aDroppedFiles[$i],"\")
                                $file=$file[$file[0]]
                GUICtrlCreateListViewItem($file&"|"&$aDroppedFiles[$i], $ListView)
            Next
            GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
    EndSwitch
WEnd

Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
   
    $aDroppedFiles = 0
    Dim $aDroppedFiles[$nAmt[0]+1]
   
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
            DllStructGetPtr($pFileName), "int", $nSize)
        
        $aDroppedFiles[0] += 1
        
        $aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
   
    ReDim $aDroppedFiles[$aDroppedFiles[0]+1]
EndFunc[/au3]
发表于 2009-4-27 12:38:07 | 显示全部楼层
本帖最后由 131738 于 2009-4-27 18:50 编辑

、、、、、、、、、、、、、、、、、、、、、、、、
 楼主| 发表于 2009-4-27 12:43:53 | 显示全部楼层
谢谢大绯狼的回复,你的脚本运行后,我拖放文件弹出一个出差的对话框,说解析函数call错误,请问是怎么回事?
发表于 2009-4-27 15:07:14 | 显示全部楼层
我这里3.2.9+WINXP运行正常
发表于 2009-4-27 18:22:03 | 显示全部楼层
我这里3.3.0+WINXP运行也正常
 楼主| 发表于 2009-4-28 09:48:21 | 显示全部楼层
我这里3.3.0+WINXP,拖放后弹出的错误对话框如下:
,是怎么回事呢?

本帖子中包含更多资源

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

×
发表于 2009-4-28 10:22:32 | 显示全部楼层
本帖最后由 jycel 于 2009-4-28 10:23 编辑

代码不对吧

DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _

后面有一个符号_
我刚试了下不要最后那个"_"就会出现CALL错误
发表于 2009-4-28 10:34:39 | 显示全部楼层
楼上正解~~~~~~~~~~~
 楼主| 发表于 2009-4-28 14:42:08 | 显示全部楼层

RE: 关于listview拖放问题

THANKS ,解决了!
发表于 2009-9-13 09:17:44 | 显示全部楼层
大非狼高手也
发表于 2011-10-22 15:11:24 | 显示全部楼层
然后实现拖入文件夹递归 下面的文件了  求教  感谢
发表于 2014-7-16 17:51:31 | 显示全部楼层
为什么我的运行报错啊
发表于 2014-7-16 21:10:42 | 显示全部楼层
本帖最后由 chzj589 于 2014-7-16 21:14 编辑

回复 9# jycel

DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
这样也不会
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
DllStructGetPtr($pFileName), "int", $nSize)
上下两排要靠近就不会
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 06:19 , Processed in 0.104161 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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