如何在WM_DROPFILES() 中返回文件的大小,创建时间等和文件的相关信息?[已解决]
本帖最后由 xwt620 于 2011-11-24 01:07 编辑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 ;==>WM_DROPFILESRT,这段代码只能返回文件名,我想从这个函数中返回我需要的文件信息,然后用数组返回。
如果有这方面链接也可以。 自己在函数里面加 FileGetTime 不就行了 这个是干什么用的?能解释一下函数的参数和作用吗? 这个是干什么用的?能解释一下函数的参数和作用吗?
gzh888666 发表于 2011-11-3 03:06 http://www.autoitx.com/images/common/back.gif
这个还需要解释吗?参见GUIRegisterMsg的帮助说明
如下面的代码,你拖一堆文件到窗口,就明白 了
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Global Const $WM_DROPFILES = 0x0233
Global $hGUI, $hLV_1, $hLV_2, $idLV_2
$hGUI = GUICreate("Test", 400, 400, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
ConsoleWrite("$hGUI = " & $hGUI & @LF)
$hLV_1 = _GUICtrlListView_Create($hGUI, "", 5, 5, 390, 190)
ConsoleWrite("$hLV_1 = " & $hLV_1 & @LF)
_GUICtrlListView_InsertColumn($hLV_1, 0, "LV1: File Name", 120)
$idLV_2 = GUICtrlCreateListView("", 5, 200, 390, 190)
$hLV_2 = ControlGetHandle($hGUI, "", $idLV_2)
ConsoleWrite("$hLV_2 = " & $hLV_2 & @LF)
_GUICtrlListView_InsertColumn($hLV_2, 0, "LV2: File Name", 120)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
ConsoleWrite("WM_DROPFILES_FUNC:$hWnd = " & $hWnd & @LF)
Switch $hWnd
Case $hGUI
Local Const $tagPOINT = "int X;int Y"
Local $tPOINT = DllStructCreate($tagPOINT), $iX, $iY
Local $aRET, $hCtrl, $nSize, $tFileName
$aRET = DllCall("shell32.dll", "int", "DragQueryPoint", "hwnd", $wParam, "ptr", DllStructGetPtr($tPOINT))
$iX = DllStructGetData($tPOINT, "X")
$iY = DllStructGetData($tPOINT, "Y")
$hCtrl = _GetCtrlHandleFromPoint($iX, $iY)
ConsoleWrite("$iX = " & $iX & "; $iY = " & $iY & "; $hCtrl = " & $hCtrl & @LF)
Switch $hCtrl
Case $hLV_1, $hLV_2
$aRET = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
For $i = 0 To $aRET - 1
$nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
$nSize = $nSize + 1
$tFileName = DllStructCreate("char[" & $nSize & "]")
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($tFileName), "int", $nSize)
_GUICtrlListView_AddItem($hCtrl, DllStructGetData($tFileName, 1))
$tFileName = 0
Next
Return 0
EndSwitch
EndSwitch
EndFunc
Func _GetCtrlHandleFromPoint($iX, $iY)
$aLV_Pos = ControlGetPos($hGUI, "", $hLV_1)
If ($iX >= $aLV_Pos) And ($iX <= $aLV_Pos + $aLV_Pos) And ($iY >= $aLV_Pos) And ($iY <= $aLV_Pos + $aLV_Pos) Then
Return $hLV_1
Else
$aLV_Pos = ControlGetPos($hGUI, "", $hLV_2)
If ($iX >= $aLV_Pos) And ($iX <= $aLV_Pos + $aLV_Pos) And ($iY >= $aLV_Pos) And ($iY <= $aLV_Pos + $aLV_Pos) Then
Return $hLV_2
Else
Return 0
EndIf
EndIf
EndFunc
这个方法我找了好久了 谢谢lz和楼上的 回复 2# afan
回afan大大,我知道用FileGetSize、FileGetTime可以获取文件相关的信息,但是我看到很多源码里用DllStructGetData函数返回信息很方便,其实我也是想学习下DllStructGetData函数,但是苦于找不到好的学习资料。 回复 5# kyniel
这个帖子有更多功能,建议可以去看下http://www.autoitx.com/thread-28496-1-1.html
页:
[1]