Jump to content



Photo

DragDropEvent UDF - Handle OLE DragDrop Event


  • Please log in to reply
9 replies to this topic

#1 Ward

Ward

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 09 March 2012 - 03:41 AM

To deal with OLE drag-and-drop event is painful in autoit. Here is an exmaple from ProgAndy (thanks). But since we have AutoItObject UDF, it should go easy. However, there are still a lot of works to do. So I wrote the UDF to convert OLE drag-and-drop event to "Windows Message" event that can be easily handled by GUIRegisterMsg() in AutoIt.

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:

AutoIt         
#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 ==
AutoIt         
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 ==

AutoIt 3.3.8.0
AutoItObject UDF by AutoItObject-Team
Associative Array UDF by Ward
Binary UDF by Ward

Attachment not includes above requirement files, but includes more examples.

== 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().

Attached File  DragDropEvent.zip   5.59K   349 downloads

Edited by Ward, 15 March 2012 - 07:51 AM.






#2 trancexx

trancexx

    Hm, I really shouldn't.

  • Active Members
  • PipPipPipPipPipPip
  • 5,191 posts

Posted 09 March 2012 - 06:56 AM

Excellent as always with you.

Are you sure you got the x64 issue correctly. By looking at the code the problem with x64 could be struct parameter for methods of that interface. You have used POINTL = uint;uint logic, but that's valid only for x86 (it should be long;long btw).

eMyvnE


#3 macwcodvs

macwcodvs

    Seeker

  • Active Members
  • 18 posts

Posted 09 March 2012 - 06:59 AM

good examples
but dunno where u can use it
$WS_EX_ACCEPTFILES for me it enough
don't know englishSome advertising from me:

GOM Media Player---addon for gom player autosave playlist


#4 Ward

Ward

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 09 March 2012 - 07:50 AM

@trancexx
Thank you for always find the problem. :oops:
Now I use uint64 to receive the POINTL struct. It works both x86 and x64.

@macwcodvs
$WS_EX_ACCEPTFILES and $WM_DROPFILES are what I use before.
If you don't want to handle text and mouse enter / leave / over event. They are enough.
I wrote these UDF because my new program need to drag files to a TreeView control. However, when use WM_DROPFILES, I don't know where to insert the new node.

#5 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 09 March 2012 - 03:15 PM

Could this be updated to use the new internal ObjCreateInterface function? That would remove the req for AutoItObject.

Edited by wraithdu, 09 March 2012 - 03:16 PM.


#6 Ward

Ward

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 10 March 2012 - 01:05 AM

@wraithdu, using ObjCreateInterface need to write a replacement of _AutoItObject_ObjectFromDtag.
It should not hard, just copy the code from AutoItObject.au3...

#7 Ward

Ward

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 10 March 2012 - 04:39 AM

@wraithdu, I just done what you suggested !

Since need to rewrite _AutoItObject_ObjectFromDtag, I also removed a memory leakage and the dependency to associative array UDF (instead of using associative array, I store the hwnd data just in the interface vtable).

#8 trancexx

trancexx

    Hm, I really shouldn't.

  • Active Members
  • PipPipPipPipPipPip
  • 5,191 posts

Posted 10 March 2012 - 07:05 AM

By using built-in function you have some new data types available, like struct*. If you specify that inside description strings instead of ptr, you don't need tedious DllStructGetPtr() every time you try to pass pointer of a struct.
struct* will accept either pointer or a structure itself (in which case it will query for pointer internally).

Edited by trancexx, 10 March 2012 - 07:05 AM.

eMyvnE


#9 Saiph

Saiph

    Seeker

  • Normal Members
  • 2 posts

Posted 22 July 2012 - 10:36 AM

Hi,
your udf is wonderful and works with Opera and Chrome but not with Firefox. When I drag and drop an image from Firefox to a your example Gui it says me C:UsersmyuserAppDataLocalTempagkri35bho.bmp and not the internet address.
Can you suufest me a solution?
Thanks

#10 prazetto

prazetto

    Seeker

  • Active Members
  • 44 posts

Posted 16 April 2013 - 05:28 AM

@Saiph

Thats aren't UDF fault but what browser like Mozillia Firefox or Seamonkey add to DragDrop source.

In the verge of death

 

Graphical Button [Sizable, pure AutoIt3 script & equal with ActiveX control quality]

Graphical AutoIt3 Control (Button and Progressbar, Next Generation of Graphical Button)

Virtuallization UDF (Virtual File, DLL and ActiveX Virtualization Solution on AutoIt3)

GTK+ Widgets Framework UDF (Implementation of GTK+)

Skin UDF (Change Form Skin. No less No more...)

 

My Official Site

 

Site : http://www.seagea.com

 

logo.png





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users