这个是干什么用的?能解释一下函数的参数和作用吗?
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
|