Drag Drop Files...

Creating complex macros, dialogs, solving complex tasks, programming.

Drag Drop Files...

Postby TheVig on Sun Sep 07, 2008 11:14 am

How exactly do you set up a dialog to receive files dropped into it....

For example...
An MP3 dragged into a dialog will add the file path to the list box.

I see the WM_QM_DRAGDROP event and the WS_ES_ACCEPTFILES style...but I've tried to test a simple out "text" test and can't get that to work...what gives?

Thanks.
Jimmy Vig.
TheVig
Active Member
 
Posts: 979
Joined: Thu Feb 14, 2008 9:22 am

Re: Drag Drop Files...

Postby redbull2k on Sun Sep 07, 2008 8:07 pm

Something Like this will do it

Function DROP     ?
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "3"
str lb3
if(!ShowDialog("DROP" &DROP &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230101 0x210 0 0 222 76 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030002 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 16)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,str s.getl(di.files 0) ;;get first file
,LB_Add(id(3 hDlg)s)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

redbull2k
 
Posts: 166
Joined: Fri Sep 28, 2007 4:52 am

Re: Drag Drop Files...

Postby TheVig on Mon Sep 08, 2008 5:20 am

That's what I was looking for. Thanks!

Another question about dragdrop...how do you drop a folder and populate the listbox with the contents of that directory. I'm gonna give it a wirl myself, but if anyone has a quick example ready that would be nice :)

Also, how do you drag drop multiple files...this example only gets the first one...I'm working on this too...but again, example?
I see that the di.files 0 is the trick...So I am assuming it is a "for" function...So I'll need to know how many items are selected.

Thanks again.
Jimmy Vig
TheVig
Active Member
 
Posts: 979
Joined: Thu Feb 14, 2008 9:22 am

Re: Drag Drop Files...

Postby TheVig on Mon Sep 08, 2008 6:31 am

This works...but really I know there is a better way if I could only get the number of files being dropped.
Function DROP     ?
,_i=0
,rep
,,str s.getl(di.files _i) ;;get first file
,,if s=""
,,,ret
,,LB_Add(id(3 hDlg)s)
,,_i+1


any ideas or answers?
TheVig
Active Member
 
Posts: 979
Joined: Thu Feb 14, 2008 9:22 am

Re: Drag Drop Files...

Postby Gintaras on Mon Sep 08, 2008 6:44 am

Function DROP     ?
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "3"
str lb3
if(!ShowDialog("DROP" &DROP &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230101 0x210 0 0 222 76 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030002 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 16)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,int hlb=id(3 hDlg)
,str s
,foreach s di.files
,,if(dir(s 1)) ;;folder
,,,s+"\*"
,,,Dir d
,,,foreach(d s FE_Dir)
,,,,str sPath=d.FileName(1)
,,,,LB_Add(hlb sPath)
,,else ;;file
,,,LB_Add(hlb s)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1



To get number of dropped files use numlines(di.files).
Gintaras
Site Admin
 
Posts: 10411
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Drag Drop Files...

Postby TheVig on Mon Sep 08, 2008 6:47 am

Neat.
TheVig
Active Member
 
Posts: 979
Joined: Thu Feb 14, 2008 9:22 am

Re: Drag Drop Files...

Postby r0n on Tue Dec 05, 2017 7:33 pm

How do you approach a situation where you have multiple input-fields that can receive drag/drop?

From the help-file:
case WM_INITDIALOG
QmRegisterDropTarget(id(3 hDlg) hDlg 16)
case WM_DESTROY
case WM_COMMAND goto messages2
case WM_QM_DRAGDROP
QMDRAGDROPINFO& di=+lParam
set edit box
str s.getl(di.files 0) ;;get first file
s.setwintext(id(3 hDlg))
to get all dropped files, you can use eg foreach. Example: foreach(s di.files) out s


Within the case "case WM_QM_DRAGDROP" you have:
s.setwintext(id(3 hDlg))

But how do you process 2 inputfields, for example inputfields with ID 3 (like you see above) and an extra one with ID 4.
If the user drags a file onto inputfield with ID 4 how can you make the code use the correct inputfield?

EDIT:
Assuming In the WM_INITDIALOG part you would have (for ID 3 and 4):
QmRegisterDropTarget(id(3 hDlg) hDlg 16)
QmRegisterDropTarget(id(4 hDlg) hDlg 16)
r0n
Active Member
 
Posts: 500
Joined: Tue Jul 24, 2012 5:47 am

Re: Drag Drop Files...

Postby Gintaras on Tue Dec 05, 2017 7:43 pm

QMDRAGDROPINFO.hwndTarget should be the control.
Gintaras
Site Admin
 
Posts: 10411
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Drag Drop Files...

Postby r0n on Tue Dec 05, 2017 9:42 pm

Ah!
Thank you!
r0n
Active Member
 
Posts: 500
Joined: Tue Jul 24, 2012 5:47 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest