Link to home
Start Free TrialLog in
Avatar of expertfan
expertfan

asked on

Dragacceptfiles on a form with multiple controls....

i have a form with multiple textboxes, listboxes and command buttons. now the requirement is if i drag and drop file(s) from 'windows explorer', how can i get the OleDragDrop event of the form triggerred regardless of where the users 'drops' the files [i.e regardless of on which control the user releases the mouse]
Avatar of lunchbyte
lunchbyte

For the controls oledragdrop event, just call the form oledragdrop event

Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_OLEDragDrop data, effect, button, shift, x, y
End Sub


Avatar of expertfan

ASKER

no i don't want to code in every controls oledgradrop event, i am looking for a generic solution so that it can handled at a common place like 'forms oledragdrop event'
Avatar of Mike Tomlinson
This is an unfortunate limitation of VB6...there isn't any way to make global event handlers (other than control arrays consisting of the same type of control) except by adding code all over the place.

If you want dynamic event handling then move on up to VB.Net....
really???

can't we handle the oledragdrop on a form if the drop happens on the controls on the form.....i hope someone should have a workaround.
What is wrong with the sample I gave you? It is not adding any work to you other then copy and paste this "Form_OLEDragDrop data, effect, button, shift, x, y" for all controls. If you have over 100 hundred controls, this will take few minutes. If you still don't want to do this then move up to VB.Net as idle mind suggested.  

If you drop on a text box, the form oledragdrop event is not fired so no, it will not work. that is why I suggested to call the routine from each control.
"can't we handle the oledragdrop on a form if the drop happens on the controls on the form"

Yes you can...

lunchbyte gave you that solution already:

    Private Sub text_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
        Form_OLEDragDrop data, effect, button, shift, x, y
    End Sub

The drop above is occuring in the "text" control and he is then passing that info along to the forms OLEDragDrop "event handler" sub.

Of course you have to do this for every control that you want "passed on"!

There may be a solution using subclassing...would have to go searching...
yes my current code is exactly what you said, every control i have the oledragdrop event coded :)

i am looking for a better solution.
ASKER CERTIFIED SOLUTION
Avatar of quarkphoton
quarkphoton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found a subclassing example by wpsjr1 here:
https://www.experts-exchange.com/questions/11678998/Drag-and-drop-file.html#4945622

A quick test allowed the drop to be made on any control on the form.

I just changed the Forms code to hook the form instead of a flexgrid:

Option Explicit

Private Sub Form_Load()
  DragAcceptFiles Me.hwnd, 1   ' begin accepting
  Hook Me.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
  UnHook Me.hwnd
  DragAcceptFiles Me.hwnd, 0   ' stop accepting
End Sub
If you have multiple dropped files you can use this routine, same as Idle Minds except that example will only throw out the first dropped file in the buffer.

https://www.experts-exchange.com/questions/22010741/Drag-and-Drog-Desktop-Shortcut.html
thanks quarkphoton!!