Try the following fangles. Drag from explorer to the main window. If it works then the file names should be shown in the debugger.
This uses OLE drop handling which, behind the scenes, should be the way the PB drag/drop lib is doing it. The other possibility is already covered by one of Rashad's posts (#WM_DROPFILES) and you had that working.
If this code works then the fault is definitely with PB's lib.
I think it more likely though that the code will fail and the fault lies elsewhere.
Code: Select all
Structure _IDropTarget
*vTable
refCount.i
blnAllowDrop.i
EndStructure
OleInitialize_(0)
#Window = 0
If OpenWindow(#Window, 0, 0, 800, 600, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
*this._IDropTarget = AllocateMemory(SizeOf(_IDropTarget))
*this\vTable = ?VTable_IDropTarget
RegisterDragDrop_(WindowID(#Window), *this) ; declare our gadget as a potential drop target
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
End
;-Drop enable function.
;-Internal functions.
;/////////////////////////////////////////////////////////////////////////////////
;*pdwEffect guaranteed to be non-null.
Procedure DropTarget_SetEffects(grfKeyState, *pdwEffect.LONG)
If grfKeyState&#MK_CONTROL
If *pdwEffect\l & #DROPEFFECT_COPY
*pdwEffect\l = #DROPEFFECT_COPY
Else
*pdwEffect\l = #DROPEFFECT_NONE
EndIf
ElseIf *pdwEffect\l & #DROPEFFECT_MOVE
*pdwEffect\l = #DROPEFFECT_MOVE
Else
*pdwEffect\l = #DROPEFFECT_NONE
EndIf
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;-iDropTarget methods.
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_QueryInterface(*this._IDropTarget, iid, *ppvObject.INTEGER)
Protected result
If CompareMemory(iid, ?IID_IUnknown, SizeOf(CLSID)) Or CompareMemory(iid, ?IID_IDropTarget, SizeOf(CLSID))
*ppvObject\i = *this
*this\refCount + 1
result = #S_OK
Else
*ppvObject\i=0
result = #E_NOINTERFACE
EndIf
ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_AddRef(*this._IDropTarget)
*this\refCount + 1
ProcedureReturn 0
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_Release(*this._IDropTarget)
Protected result
*this\refCount - 1
If *this\refCount > 0
result = *this\refCount
Else
FreeMemory(*this)
EndIf
ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragEnter(*this._IDropTarget, dataObject.IDataobject, grfKeyState, pt.q, *pdwEffect.LONG)
Protected result=#S_OK, thisFormatEtc.FORMATETC
*this\blnAllowDrop = #False
If *pdwEffect = 0
result = #E_INVALIDARG
Else
;Check to see if the data object supports our text format.
With thisFormatEtc
\cfFormat = #CF_HDROP
\dwAspect = #DVASPECT_CONTENT
\lindex = -1
\tymed = #TYMED_HGLOBAL
EndWith
If dataObject\QueryGetData(thisFormatEtc) = #S_OK
*this\blnAllowDrop = #True
DropTarget_SetEffects(grfKeyState, *pdwEffect)
Else
*pdwEffect\l = #DROPEFFECT_NONE
EndIf
EndIf
ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragOver(*this._IDropTarget, grfKeyState, pt.q, *pdwEffect.LONG)
Protected result = #S_OK
If *pdwEffect = 0
result = #E_INVALIDARG
Else
If *this\blnAllowDrop
DropTarget_SetEffects(grfKeyState, *pdwEffect)
Else
*pdwEffect\l = #DROPEFFECT_NONE
EndIf
EndIf
ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragLeave(*this._IDropTarget)
ProcedureReturn #S_OK
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////
;*pdwEffect\l contains the original combination of effects.
Procedure.i DropTarget_Drop(*this._IDropTarget, Dataobject.IDataobject, grfKeyState, pt.q, *pdwEffect.LONG)
Protected result = #S_OK, anchWnd, tempAnchWnd, thisFormatEtc.FORMATETC, thisStgMedium.STGMEDIUM, *ptrChar.CHARACTER
If *pdwEffect = 0
result = #E_INVALIDARG
ElseIf *this\blnAllowDrop
;Set effects.
DropTarget_SetEffects(grfKeyState, *pdwEffect)
;Do we proceed?
If *pdwEffect\l <> #DROPEFFECT_NONE
;Retrieve the data. We have previously checked for valid data.
;Windows automatically converts between #CF_TEXT and #CF_UNICODETEXT as appropriate.
With thisFormatEtc
\cfFormat = #CF_HDROP
\dwAspect = #DVASPECT_CONTENT
\lindex = -1
\tymed = #TYMED_HGLOBAL
EndWith
If Dataobject\GetData(thisFormatEtc, thisStgMedium) = #S_OK
If thisStgMedium\hGlobal ;Only prudent to be sure here!
buffer = AllocateMemory(1024)
If buffer
numFiles = DragQueryFile_(thisStgMedium\hGlobal, -1, 0, 0)
For i = 0 To numFiles-1
DragQueryFile_(thisStgMedium\hGlobal, i, buffer, 1024)
Debug PeekS(buffer)
Next
FreeMemory(buffer)
EndIf
EndIf
ReleaseStgMedium_(thisStgMedium)
Else
result = #E_FAIL
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
DataSection
VTable_IDropTarget:
Data.i @DropTarget_QueryInterface()
Data.i @DropTarget_AddRef()
Data.i @DropTarget_Release()
Data.i @DropTarget_DragEnter()
Data.i @DropTarget_DragOver()
Data.i @DropTarget_DragLeave()
Data.i @DropTarget_Drop()
CompilerIf Defined(IID_IUnknown, #PB_Label) = 0
IID_IUnknown: ;"{00000000-0000-0000-C000-000000000046}"
Data.l $00000000
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
CompilerEndIf
CompilerIf Defined(IID_IDropTarget, #PB_Label) = 0
IID_IDropTarget: ;{00000122-0000-0000-C000-000000000046}
Data.l $00000122
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
CompilerEndIf
EndDataSection
I may look like a mule, but I'm not a complete ass.