找回密码
 加入
搜索
查看: 1861|回复: 6

[AU3基础] 如何在WM_DROPFILES() 中返回文件的大小,创建时间等和文件的相关信息?[已解决]

  [复制链接]
发表于 2011-11-3 00:11:33 | 显示全部楼层 |阅读模式
本帖最后由 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[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   ;==>WM_DROPFILES
RT,这段代码只能返回文件名,我想从这个函数中返回我需要的文件信息,然后用数组返回。
如果有这方面链接也可以。
发表于 2011-11-3 01:54:58 | 显示全部楼层
自己在函数里面加 FileGetTime 不就行了
发表于 2011-11-3 03:06:50 | 显示全部楼层
这个是干什么用的?能解释一下函数的参数和作用吗?
发表于 2011-11-3 07:54:30 | 显示全部楼层
这个是干什么用的?能解释一下函数的参数和作用吗?
gzh888666 发表于 2011-11-3 03:06


这个还需要解释吗?参见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[0] - 1
                        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
                        $nSize = $nSize[0] + 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[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
        Return $hLV_1
    Else
        $aLV_Pos = ControlGetPos($hGUI, "", $hLV_2)
        If ($iX >= $aLV_Pos[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
            Return $hLV_2
        Else
            Return 0
        EndIf
    EndIf
EndFunc
发表于 2011-11-3 14:48:21 | 显示全部楼层
这个方法我找了好久了 谢谢lz和楼上的
 楼主| 发表于 2011-11-3 23:23:09 | 显示全部楼层
回复 2# afan


    回afan大大,我知道用FileGetSize、FileGetTime可以获取文件相关的信息,但是我看到很多源码里用DllStructGetData函数返回信息很方便,其实我也是想学习下DllStructGetData函数,但是苦于找不到好的学习资料。
 楼主| 发表于 2011-11-3 23:24:57 | 显示全部楼层
回复 5# kyniel


    这个帖子有更多功能,建议可以去看下http://www.autoitx.com/thread-28496-1-1.html
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 05:43 , Processed in 0.087825 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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