Hey guys,

I understand the Shell32.lib functions, they're really straightforward. But I can't figure out what a Drag and Drop structure should look like. And yes, I did a google for it.

Appreciate your help,
Homer
Posted on 2003-03-22 14:39:49 by Homer
If your app is to be a D&D target, implement IDropTarget interface. If your app is to be a D&D source, implement IDropSource and IDataObject interfaces.
Posted on 2003-03-22 14:55:37 by japheth
Hi Homer, You can implement Drag and Drop without the interfaces. The DragStruct is simply a list of files that have been dropped. To get the files you use DragQueryFile as follows...
DragGetNextFile proc uses edx DragStruct:DWORD,FileBuffer:DWORD


mov eax,FileBuffer
mov [eax],DWORD PTR 0

invoke DragQueryFile, DragStruct, DragQueryCounter, FileBuffer, MAX_PATH
inc DragQueryCounter

invoke DragQueryFile, DragStruct, -1, NULL,0

.IF DragQueryCounter >= eax
invoke DragFinish,DragStruct
mov DragQueryCounter,0
mov eax,-1
ret
.ENDIF

mov eax,DragQueryCounter
ret
DragGetNextFile endp
This sniplet will return the value of the each file in the structure and increment the pointer to the next file each time it's called. It's a simple way to do it but it might show you how to get the filenames. You just have to set up the control as a DragTarget then watch for the WM_DROPFILES message. When you call the function the first time you get the first file, the 2nd time the 2nd until there are no more and it returns -1

EDIT : use invoke DragQueryFile, DragStruct, -1, NULL,0 to get the number of files in the structure.
Posted on 2003-03-22 15:14:45 by donkey
If you have the MASM32-Package, there should be an Example of using Drag'n'Drop! Look for it , that helped me a lot.
Posted on 2003-03-22 15:35:04 by ChigpA
Hi Donkey,

I like your methodology of not using the interfaces. So I tried to let it sit for a few days and soak it in now and then. But I'm just as confused as I was before. I have some really basic questions that are keeping me from continuing:

Does the DragNextFile proc have to be ina certain section of my code?

Is DragNextFile to be invoked ?

Even with DragAcceptFiles set to TRUE my WM_DROPFILES doesn't do anything.


Do these questions make any sense?

You said this was easy!
Homer
Posted on 2003-03-25 10:02:59 by Homer
They make perfect sense Homer,

First the DragNextFile proc is just one that I had written for a program that I used. It had to be in that format but you can do the same in another way. The following proc can be placed anywhere. In your message loop you process the WM_DropFiles message and pass the wParam to the GetFiles proc, it will automatically go through all the files one by one, you have only to insert what you want to do with them. The GetLnkTarget proc will get the actual file name that is a target of a shortcut
IShellLink STRUCT

IUnknown Unknown <>

GetPath DWORD ?
GetIDList DWORD ?
SetIDList DWORD ?
GetDescription DWORD ?
SetDescription DWORD ?
GetWorkingDirectory DWORD ?
SetWorkingDirectory DWORD ?
GetArguments DWORD ?
SetArguments DWORD ?
GetHotkey DWORD ?
SetHotkey DWORD ?
GetShowCmd DWORD ?
SetShowCmd DWORD ?
GetIconLocation DWORD ?
SetIconLocation DWORD ?
SetRelativePath DWORD ?
Resolve DWORD ?
SetPath DWORD ?
IShellLink ENDS

IPersistFile STRUCT
IUnknown Unknown <>

GetClassID DWORD ?
IsDirty DWORD ?
Load DWORD ?
Save DWORD ?
SaveCompleted DWORD ?
GetCurFile DWORD ?
IPersistFile ENDS

.const

sIID_IShellLink textequ <{0000214EEH, 00000H, 00000H,\
{0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H}}>

sCLSID_ShellLink textequ <{000021401H, 00000H, 00000H,\
{0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H}}>

sIID_IPersistFile textequ <{00000010bH, 00000H, 00000H,\
{0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H}}>

.data

CLSID_ShellLink GUID sCLSID_ShellLink
IID_IShellLink GUID sIID_IShellLink
IID_IPersistFile GUID sIID_IPersistFile

.code

GetFiles proc hWnd:DWORD,hDrop:DWORD
LOCAL FileName[MAX_PATH] :BYTE
LOCAL nFiles :DWORD

invoke DragQueryFile, hDrop, -1, ADDR FileName, SIZEOF FileName
mov nFiles,eax

.REPEAT
dec nFiles
invoke DragQueryFile, hDrop, nFiles, ADDR FileName, SIZEOF FileName
; this line will expand LNK files to there actual file
invoke GetLinkTarget, ADDR FileName, ADDR FileName
; do what you want with the files here, they will be in Filename
; the proc will loop until there are no more files
;
.UNTIL nFiles == 0

invoke DragFinish,hDrop

ret
GetFiles endp

GetLinkTarget proc lpLINKPATH:DWORD,lpbuffer:DWORD
LOCAL psl :DWORD
LOCAL ppf :DWORD
LOCAL wsz[MAX_PATH] :WORD

invoke CoInitialize,NULL

invoke CoCreateInstance, ADDR CLSID_ShellLink, NULL, \
CLSCTX_INPROC_SERVER, ADDR IID_IShellLink, ADDR psl
.IF eax != S_OK
mov eax,-1
ret
.endif

lea eax,ppf
push eax
lea eax,IID_IPersistFile
push eax
push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.IUnknown.QueryInterface
.IF eax != S_OK
push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.IUnknown.Release

invoke CoUninitialize
ret
.endif

invoke MultiByteToWideChar, CP_ACP, NULL, lpLINKPATH, -1, ADDR wsz, MAX_PATH

push STGM_READ
lea eax,wsz
push eax
push ppf
mov edi,ppf
mov edi,[edi]
call [edi].IPersistFile.Load
.IF eax != S_OK
push ppf
mov edi,ppf
mov edi,[edi]
call [edi].IPersistFile.IUnknown.Release

push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.IUnknown.Release

invoke CoUninitialize
mov eax,-1
ret
.endif

push NULL
push NULL
push MAX_PATH
push lpbuffer
push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.GetPath
.IF eax != NOERROR
push ppf
mov edi,ppf
mov edi,[edi]
call [edi].IPersistFile.IUnknown.Release

push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.IUnknown.Release

invoke CoUninitialize
mov eax,-1
ret
.ENDIF

push ppf
mov edi,ppf
mov edi,[edi]
call [edi].IPersistFile.IUnknown.Release

push psl
mov edi,psl
mov edi,[edi]
call [edi].IShellLink.IUnknown.Release

invoke CoUninitialize
xor eax,eax

ret
GetLinkTarget endp

You must set the WS_EX_ACCEPTFILES Style
Posted on 2003-03-25 10:26:23 by donkey
You'll need this structure as well
Unknown STRUCT

QueryInterface DWORD ?
AddRef DWORD ?
Release DWORD ?
Unknown ends
Posted on 2003-03-25 10:36:06 by donkey
Thank you, Donkey. Your code helped me alot!!!  :D

Best regards,
Nordwind64
Posted on 2008-08-21 10:59:41 by Nordwind64