Solved

Dragacceptfiles on a form with multiple controls....

Posted on 2006-10-31
11
349 Views
Last Modified: 2008-02-01
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]
0
Comment
Question by:expertfan
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842120
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


0
 

Author Comment

by:expertfan
ID: 17842139
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'
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842732
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....
0
 

Author Comment

by:expertfan
ID: 17842755
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.
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17842791
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842793
"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...
0
 

Author Comment

by:expertfan
ID: 17842812
yes my current code is exactly what you said, every control i have the oledragdrop event coded :)

i am looking for a better solution.
0
 
LVL 2

Accepted Solution

by:
quarkphoton earned 500 total points
ID: 17842886
this can be done using subclassing....

http://www.vbcodemagician.dk/resources/dragcomponent.htm
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17842904
Found a subclassing example by wpsjr1 here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11678998.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
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 17848628
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.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22010741.html
0
 

Author Comment

by:expertfan
ID: 17878680
thanks quarkphoton!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now