关于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-27 18:49 编辑
////////////////////////////////////// #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 18:50 编辑
、、、、、、、、、、、、、、、、、、、、、、、、 谢谢大绯狼的回复,你的脚本运行后,我拖放文件弹出一个出差的对话框,说解析函数call错误,请问是怎么回事? 我这里3.2.9+WINXP运行正常 我这里3.3.0+WINXP运行也正常 我这里3.3.0+WINXP,拖放后弹出的错误对话框如下:
,是怎么回事呢? 本帖最后由 jycel 于 2009-4-28 10:23 编辑
代码不对吧
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
后面有一个符号_
我刚试了下不要最后那个"_"就会出现CALL错误 楼上正解~~~~~~~~~~~
RE: 关于listview拖放问题
THANKS ,解决了! 大非狼高手也 然后实现拖入文件夹递归 下面的文件了求教感谢 为什么我的运行报错啊 本帖最后由 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]