This UDF provides 4 kinds of message: $WM_DRAGENTER, $WM_DRAGOVER, $WM_DRAGLEAVE, and $WM_DROP. To use is easy, just register a GUI window or control as the drop target, then handle message by GUIRegisterMsg(). See example:
#Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 380, 130, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) GUICtrlCreateLabel("(Drop text or files on me)", 40, 40) DragDropEvent_Register($MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Select Case DragDropEvent_IsFile($wParam) If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY Case DragDropEvent_IsText($wParam) If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) ToolTip("(" & $X & "," & $Y & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc
== Public Functions List ==
DragDropEvent_Startup() ; DragDropEvent UDF startup. ; DragDropEvent_Register($hWnd, $hWndToReceiveMsg = $hWnd) ; Register a window or control that can be the target. $hWndToReceiveMsg is needed only when $hWnd is a control. ; DragDropEvent_Revoke($hWnd) ; Revokes the registration of the specified window or control. ; DragDropEvent_GetHWnd($wParam) ; Can invoke by all message handler, to get what window or control is the target. ; DragDropEvent_GetX($wParam) DragDropEvent_GetY($wParam) DragDropEvent_GetKeyState($wParam) ; Can invoke by all message handler except $WM_DRAGLEAVE, to get the modifier keys and mouse position. ; DragDropEvent_IsText($wParam) DragDropEvent_IsFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to check what data is being dragged. ; DragDropEvent_GetText($wParam) DragDropEvent_GetFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to get related data. Path of file is splited by "|". ;
== Requirement ==
Attachment not includes above requirement files, but includes more examples.AutoIt 3.3.8.0
AutoItObject UDF by AutoItObject-TeamAssociative Array UDF by WardBinary UDF by Ward
== Update 2012/3/10 ==
* Fix x64 problem. (Thanks to trancexx)
* Remove dependency to AutoItObject and Associative Array UDF. (Suggestion by wraithdu)
== Update 2012/3/15==
* Remove dependency to Bianry UDF.
* Remove extra DllStructGetPtr(). (Suggestion by trancexx)
* Fix bug in DataObject_GetFile().
DragDropEvent.zip 5.59K
349 downloads
Edited by Ward, 15 March 2012 - 07:51 AM.






