Drag&Drop: VB _TO_ other apps

My question is essentially the inverse of QID=857726333 (not that that helps any, I'm sure ...)

I need to be able to have a VB application act as a D&D source, with the target some other application. The trick is that I need to be able to specify what type of data is being passed.

Specifically, I want to be able to begin a drag operation in VB, from ANY control, so that the user can drop on PowerPoint (although, the target shouldn't matter). The information that I want passed along is the same information that File Manager/Explorer would sent PowerPoint if I attempted to drag&drop a file.

Really, I just want to be able to tell Windows "Hey, I'm dragging a fileName/file reference, you can do whatever you want with it when I drop it on you" - just as a File Manager / Explorer drag and drop operation does.

I've already encountered the SHELL.DLL routines to _receive_ a Drag&Drop, I need to know how to initiate this operation and specify that the destination app will receive a file / file reference (of my choosing, of course).

Thanks in Advance ...

Who is Participating?
twardConnect With a Mentor Commented:
You should (I haven't tried it) be able to use the SendMessage API call.

You would want to send the WM_DROPFILES message and the application that you dropped the file on should take it from there.....
SladeAuthor Commented:
That's fine, but I'm concerned about how to 'tell' the target application (being dropped upon) WHICH file(s) are being dropped. I realize I can use SendMessage() to send the WM_DROPFILES message, but what do I need to supply for wParam and lParam?
I either need to know the actual values, or where to find them. (I've got the Win16 SDK)

Thanks in advance,


SladeAuthor Commented:
By the way ...

All of the documentation refers to a data structure called HDROP to which I need to create a handle hDrop (WORD). I can't find ANYWHERE any reference to how this structure is defined!
If I could find the structure, I'd be finished.
Any ideas?


Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

I haven't been able to find the defined structure either....
SladeAuthor Commented:

Any other ideas of where to look? I can't do what I need to do without it  :(



SladeAuthor Commented:
In case anyone else goes looking for this information, the data structure pointed to by HDROP is undocumented. I ended up finding it in an old MSDN CD I had lying around (Apr. 1994).

It turns out the typedef for the data structure is:

typedef struct {
  WORD wSize;  // size of data structure
  POINT ptMousePos;  // position of mouse pointer on drop
  BOOL fInNonClientArea;  // mouse in non-client area on drop?
  BOOL Unicode;  // pathnames use unicode? (only for Win32 -
                 // Win16 does not have this parameter!)

The trick is that to add a filename, you have to use GlobalReAlloc() to increase the size of the data structure. The pathname(s) are appended to the end of the structure - right after the Unicode parameter. The pathnames must be preceeded by a 0-value character (chr$(0)) and followed by one:

chr$(0) + pathname + chr$(0)

The last pathname has an additional chr$(0) character to indicate that there are no more pathnames:

... + chr$(0) + pathname + chr$(0) + chr$(0)

When adding pathnames to the structure, you have to make sure that you update the wSize parameter accordingly.

Note: On Win32 systems, path names using Unicode systems require a different amound of memory to store than non-Unicode strings!

I haven't tried the above yet, I just have to figure out how to translate all the C++ code in the MSDN example into VB.

Hope this helps someone else ...


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.