Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drag Drop Files...
#1
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.
#2
Something Like this will do it

Function DROP
Code:
Copy      Help
;\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
#3
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 Smile

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
#4
This works...but really I know there is a better way if I could only get the number of files being dropped.
Function DROP
Code:
Copy      Help
,_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?
#5
Function DROP
Code:
Copy      Help
\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).
#6
Neat.
#7
How do you approach a situation where you have multiple input-fields that can receive drag/drop?

From the help-file:
Quote: 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)
#8
QMDRAGDROPINFO.hwndTarget should be the control.
#9
Ah!
Thank you!
#10
The above code, I found a problem, it does not support the drag and drop of empty folders  Huh
The following line of code, I don't understand what it means.

    QMDRAGDROPINFO& di=+lParam 

I want the edit box to support drag and drop of files, folders (including empty folders),

In addition, how to use the delete key to delete unwanted items in the list box?

I hope someone can provide an example, thank you very much


Macro drag drop
Code:
Copy      Help
;http://www.quickmacros.com/forum/showthread.php?tid=2702&pid=12511#pid12511
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ListBox 0x54230101 0x200 0 0 224 62 ""
;4 Edit 0x54030080 0x200 4 72 214 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4"
str lb3 e4
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

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
#11
The edit box supports drag and drop, I have modified it successfully, here is the code



Macro Edit_Drag Drop
Code:
Copy      Help
;http://www.quickmacros.com/forum/showthread.php?tid=2702&pid=12511#pid12511
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ListBox 0x54230101 0x200 0 0 224 62 ""
;4 Edit 0x54030080 0x200 4 72 214 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4"
str lb3 e4
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(4 hDlg) hDlg 16)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,int hlb=id(4 hDlg)
,str s=di.files
,s.setwintext(hlb)

ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Using the delete button to delete the items in the list box, has not been completed, I hope someone can provide some suggestions, thanks in advance


Forum Jump:


Users browsing this thread: 1 Guest(s)