jchang 发表于 2009-4-26 22:38:09

关于listview拖放问题

本帖最后由 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

131738 发表于 2009-4-26 23:04:07

本帖最后由 131738 于 2009-4-27 18:49 编辑

//////////////////////////////////////

大绯狼 发表于 2009-4-27 09:16:58

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>

Global Const $WM_DROPFILES = 0x0233

Global $aDroppedFiles

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]
                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+1]
   
    For $i = 0 To $nAmt - 1
      $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
      $nSize = $nSize + 1
      $pFileName = DllStructCreate("char[" & $nSize & "]")
      
      DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
            DllStructGetPtr($pFileName), "int", $nSize)
      
      $aDroppedFiles += 1
      
      $aDroppedFiles[$aDroppedFiles] = DllStructGetData($pFileName, 1)
      $pFileName = 0
    Next
   
    ReDim $aDroppedFiles[$aDroppedFiles+1]
EndFunc

131738 发表于 2009-4-27 12:38:07

本帖最后由 131738 于 2009-4-27 18:50 编辑

、、、、、、、、、、、、、、、、、、、、、、、、

jchang 发表于 2009-4-27 12:43:53

谢谢大绯狼的回复,你的脚本运行后,我拖放文件弹出一个出差的对话框,说解析函数call错误,请问是怎么回事?

大绯狼 发表于 2009-4-27 15:07:14

我这里3.2.9+WINXP运行正常

131738 发表于 2009-4-27 18:22:03

我这里3.3.0+WINXP运行也正常

jchang 发表于 2009-4-28 09:48:21

我这里3.3.0+WINXP,拖放后弹出的错误对话框如下:
,是怎么回事呢?

jycel 发表于 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

楼上正解~~~~~~~~~~~

jchang 发表于 2009-4-28 14:42:08

RE: 关于listview拖放问题

THANKS ,解决了!

yokoliu 发表于 2009-9-13 09:17:44

大非狼高手也

today2004 发表于 2011-10-22 15:11:24

然后实现拖入文件夹递归 下面的文件了求教感谢

nqawen 发表于 2014-7-16 17:51:31

为什么我的运行报错啊

chzj589 发表于 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)
上下两排要靠近就不会
页: [1]
查看完整版本: 关于listview拖放问题