BarryG wrote: Sat Oct 08, 2022 3:06 amYou just have to change the SetWindowLongPtr_() line in that post to use GadgetID(#CanvasGadget) instead of "hWND".
I updated that post for you ->
viewtopic.php?p=590043#p590043
Thanks BarryG. That worked, although when I plugged it into my program, it still didn't work.
After some investigating, it appears that the drag and drop for the gadget is being blocked by being inside a frame. The only way I can get it to work is if I set the drag and drop up for the frame itself:
Code: Select all
Procedure EnableGadgetFileDropAdmin(Gadget.i)
ChangeWindowMessageFilter_(#WM_DROPFILES, #MSGFLT_ADD)
ChangeWindowMessageFilter_(#WM_COPYDATA, #MSGFLT_ADD)
ChangeWindowMessageFilter_(73, #MSGFLT_ADD)
SetWindowLongPtr_(GadgetID(Gadget), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(Gadget), #GWL_EXSTYLE) | #WS_EX_ACCEPTFILES)
EndProcedure
Procedure.s GetDroppedFile()
Protected.l Dropped, Num, Index, Size
Protected FileName$, PhraseFilename$ = ""
Dropped = EventwParam()
Num = DragQueryFile_(Dropped, - 1, "", 0) - 1
For Index = 0 To Num
Size = DragQueryFile_(Dropped, Index, 0, 0)
FileName$ = Space(Size)
DragQueryFile_(Dropped, Index, FileName$, Size + 1)
Debug "File ''" + FileName$ + "'' Dropped"
Next
DragFinish_(Dropped)
ProcedureReturn FileName$
EndProcedure
Enumeration
#FrameGadget
#ImageGadget
EndEnumeration
OpenWindow(0, 0, 0, 640, 480, "Drag and Drop Test Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateImage(0, 600, 440, 32, #PB_Image_Transparent)
FrameGadget(#FrameGadget, 5, 5, 630, 470, "Frame")
ImageGadget(#ImageGadget, 20, 20, 600, 440, ImageID(0), #PB_Image_Border)
EnableGadgetFileDropAdmin(#FrameGadget) ; <- If changed to #ImageGadget, it doesn't work
Repeat
Select WaitWindowEvent()
Case #WM_DROPFILES
GetDroppedFile()
Case #PB_Event_CloseWindow
ExitProgram = 1
EndSelect
Until ExitProgram = 1
Although better, it's still not ideal as the frame in the program I'm working on is a larger area than the gadget I'm trying to set up for the drag and drop.
Kind regards,
Francis