Hi,
in meinen Skripten habe ich gemerkt, dass ich verschiedene Arten habe wie der Skriptbereich aussieht wo ich Dateien auf eine GUI ziehe.
Was von den folgenden Methoden ist besser? Oder ist es egal?
Spoiler anzeigen
AutoIt
#Region ;************ Includes ************
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************
Global $aFileList
Opt("GUIOnEventMode", 1)
Global $GUI = GUICreate("Test", 100, 100, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
;mehrere Dateien auf die GUI ziehen und so einlesen
Global $g_hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
Global $g_pDll = DllCallbackGetPtr($g_hDll)
Global $g_hProc = _WinAPI_SetWindowLong($GUI, $GWL_WNDPROC, $g_pDll)
_WinAPI_DragAcceptFiles($GUI)
While 1
Sleep(10)
WEnd
Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_DROPFILES
$aFileList = _WinAPI_DragQueryFileEx($wParam)
_WinAPI_DragFinish($wParam)
_WinAPI_MessageBeep(0) ;Ton erzeugen
For $i = 1 To UBound($aFileList) - 1
ConsoleWrite($aFileList[$i] & @CR)
Next
Return 0
EndSwitch
Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_WinProc
Func _beenden()
;mehrere Dateien auf die GUI ziehen und so einlesen
_WinAPI_SetWindowLong($GUI, $GWL_WNDPROC, $g_hProc)
DllCallbackFree($g_hDll)
Exit
EndFunc ;==>_beenden
Alles anzeigen
Spoiler anzeigen
AutoIt
#Region ;************ Includes ************
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************
Opt("GUIOnEventMode", 1)
Global $GUI = GUICreate("Test", 100, 100, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
GUIRegisterMsg(0x233, "On_WM_DROPFILES")
While 1
Sleep(10)
WEnd
Func On_WM_DROPFILES($hWnd, $msg, $wParam, $lParam)
Local $tDrop, $aRet, $iCount
;string buffer for file path
$tDrop = DllStructCreate("char[260]")
;get file count
$aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
"hwnd", $wParam, _
"uint", -1, _
"ptr", DllStructGetPtr($tDrop), _
"int", DllStructGetSize($tDrop) _
)
$iCount = $aRet[0]
;get file paths
For $r = 0 To $iCount - 1
$aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
"hwnd", $wParam, _
"uint", $r, _
"ptr", DllStructGetPtr($tDrop), _
"int", DllStructGetSize($tDrop) _
)
Sleep(10)
ConsoleWrite(DllStructGetData($tDrop, 1) & @cr)
Next
;finalize
DllCall("shell32.dll", "int", "DragFinish", "hwnd", $wParam)
Return
EndFunc ;==>On_WM_DROPFILES
Func _beenden()
Exit
EndFunc ;==>_beenden
Alles anzeigen