Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Let all editbox support drag and drop files and texts
#1
hello everyone,

The following code, the first editbox, only supports drag and drop files

1.How to quickly make all editbox support drag and drop operation?

2.How to make all editbox support drag and drop texts?


complicated to implement? This is a very useful function. Thanks in advance

Macro Macro9
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out e3

#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=di.files
,s.setwintext(hlb)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
This should do it for you

Function Function3
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out e3

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 16)
,QmRegisterDropTarget(id(4 hDlg) hDlg 16)
,QmRegisterDropTarget(id(5 hDlg) hDlg 16)
,QmRegisterDropTarget(id(6 hDlg) hDlg 16)
,QmRegisterDropTarget(id(7 hDlg) hDlg 16)
,QmRegisterDropTarget(id(8 hDlg) hDlg 16)
,QmRegisterDropTarget(id(9 hDlg) hDlg 16)
,QmRegisterDropTarget(id(10 hDlg) hDlg 16)
,QmRegisterDropTarget(id(11 hDlg) hDlg 16)
,QmRegisterDropTarget(id(12 hDlg) hDlg 16)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,str s=di.files
,s.setwintext(di.hwndTarget)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
Thanks a lot, very nice example. Can it support drag and drop text?
#4
for drag and drop text need this member function

Member function QMDRAGDROPINFO.GetText
Code:
Copy      Help
function! str&s [flags] ;;flags: 1 drag source must not delete text

;Extracts dropped text.
;Returns 1 if successful, 0 if failed.


s.fix(0)

int k=GetMod
sel(k) case [0,2] case else this.effect=DROPEFFECT_NONE; ret
if(flags&1) k=2

int i
for(i 0 this.formats.len) if(this.formats[i].cfFormat=CF_UNICODETEXT) break
if(i=this.formats.len) ret

STGMEDIUM sm
this.dataObj.GetData(&this.formats[i] &sm); err ret

int gs=GlobalSize(sm.hGlobal)-2; if(gs<=0) ret
s.all(gs 2)
byte* m=GlobalLock(sm.hGlobal); if(!m) ret
memcpy s m s.len
GlobalUnlock sm.hGlobal
ReleaseStgMedium(&sm)
s.ansi

sel k
,case 0 this.effect&DROPEFFECT_MOVE
,case 2 this.effect&DROPEFFECT_COPY

ret 1

to create a member function. On Qm main window click file->New->New Member Function name it
QMDRAGDROPINFO.GetText
 just like its written then  copy code here and paste code in this member function.

an example with your dialog
Function DialogDragDropTextExample
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out e3

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 0)
,QmRegisterDropTarget(id(4 hDlg) hDlg 0)
,QmRegisterDropTarget(id(5 hDlg) hDlg 0)
,QmRegisterDropTarget(id(6 hDlg) hDlg 0)
,QmRegisterDropTarget(id(7 hDlg) hDlg 0)
,QmRegisterDropTarget(id(8 hDlg) hDlg 0)
,QmRegisterDropTarget(id(9 hDlg) hDlg 0)
,QmRegisterDropTarget(id(10 hDlg) hDlg 0)
,QmRegisterDropTarget(id(11 hDlg) hDlg 0)
,QmRegisterDropTarget(id(12 hDlg) hDlg 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s)) ret
,,s.setwintext(di.hwndTarget)
,,ret DT_Ret(hDlg 1)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#5
Make editbox drag and drop text and files be supported at the same time? Is it possible?

How to copy text instead of deleting it

[Image: a.gif]
#6
for # 2 change 
Code:
Copy      Help
if(!di.GetText(s)) ret
to
Code:
Copy      Help
if(!di.GetText(s 1)) ret
#7
try this it should be what you need
Function Function3
Code:
Copy      Help
case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,str s
,if(!di.GetText(s)) s=di.files
,s.setwintext(di.hwndTarget)
,ret DT_Ret(hDlg 1)
,
,s.setwintext(di.hwndTarget)
#8
change to
Code:
Copy      Help
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s 1)) s=di.files
,,s.setwintext(di.hwndTarget)
,,ret DT_Ret(hDlg 1)
#9
sorry kev didnt see your post.
#10
thanks a lot @Kevin @redbull2k

Here's the final code, Very good example, supporting drag and drop files and text
Note:
need to combine the member function of # 4 by@kevin

Member function QMDRAGDROPINFO.GetText

Macro Macro15
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out e3
out e4
out e5
out e6
out e7
out e8
out e9
out e10
out e11
out e12

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 0)
,QmRegisterDropTarget(id(4 hDlg) hDlg 0)
,QmRegisterDropTarget(id(5 hDlg) hDlg 0)
,QmRegisterDropTarget(id(6 hDlg) hDlg 0)
,QmRegisterDropTarget(id(7 hDlg) hDlg 0)
,QmRegisterDropTarget(id(8 hDlg) hDlg 0)
,QmRegisterDropTarget(id(9 hDlg) hDlg 0)
,QmRegisterDropTarget(id(10 hDlg) hDlg 0)
,QmRegisterDropTarget(id(11 hDlg) hDlg 0)
,QmRegisterDropTarget(id(12 hDlg) hDlg 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,;if(!di.GetText(s 1)) ret ;;Drag text only @kevin
,,if(!di.GetText(s 1)) s=di.files ;;drag file and text supported @redbull2k
,,s.setwintext(di.hwndTarget)
,,ret DT_Ret(hDlg 1)

ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#11
@Kevin

Add multi paragraph text, achieved by dragging?

Now The text I drag the second time will replace the text I drag the first time

It will be more convenient if can drag and drop some texts for many times

In addition, now press enter in the edit box to create a new line, which will close the dialog box

Macro Macro4
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 352 220 "Dialog" "4"
;3 Edit 0x54030084 0x200 12 8 330 180 ""
;1 Button 0x54030001 0x4 244 196 48 14 "OK"
;2 Button 0x54030000 0x4 300 196 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""

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

out e3

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,;if(!di.GetText(sd 1)) ret ;;
,,if(!di.GetText(s 1)) s=di.files ;;
,,s.setwintext(di.hwndTarget)
,,ret DT_Ret(hDlg 1)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#12
It's probably best in this situation to switch to a multiline edit control
then enter wont close dialog.

But for future reference to prevent dialog from closing when enter key is pressed
find IDOK and add code
Code:
Copy      Help
,ifk(Y)          ;; Enter
,,ret 0
so it looks like this
Code:
Copy      Help
,case IDOK
,ifk(Y)          ;; Enter
,,ret 0

for the text erase problem  change
Code:
Copy      Help
,,s.setwintext(di.hwndTarget)
to
Code:
Copy      Help
,,s.setsel(0 di.hwndTarget)

for multiline edit control 

use this code
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 352 220 "Dialog" "4"
;3 Edit 0x54231044 0x200 12 8 330 180""
;1 Button 0x54030001 0x4 244 196 48 14 "OK"
;2 Button 0x54030000 0x4 300 196 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

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

out e3

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s 1)) s=di.files ;;
,,s.setsel(0 di.hwndTarget)
,,ret DT_Ret(hDlg 1)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#13
It works perfectly,
Qm2 implements some functions with very little code, but it is very powerful Smile
#14
@Kevin

The above multi line editbox

how to modify the font and font size? the default effect looks too small!
#15
code to change font included
Function Function414
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 352 220 "Dialog" "4"
;3 Edit 0x54231044 0x200 12 8 330 180""
;1 Button 0x54030001 0x4 244 196 48 14 "OK"
;2 Button 0x54030000 0x4 300 196 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

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

out e3

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 0)
,__Font f.Create("Tahoma" 18 0)
,f.SetDialogFont(hDlg "3")
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s 1)) s=di.files ;;
,,s.setsel(0 di.hwndTarget)
,,ret DT_Ret(hDlg 1)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#16
@kevin
I changed the font and font size, The settings are the same as those in the options dialog box,
But the final display effect is different, why?
the result, the font is bold and the space between the spaces is too small
Expected result:
the display effect of characters in edit box and code edit area is the same


[Image: pic.png]
#17
I cannot duplicate your results.
on my pc fonts match exactly.
Did you try to exit QM and reopen and see if the result is the same?
#18
Q:exit QM and reopen
YES

The operating system I use is not in English 
It's the Chinese version Win7 64 bit. Is it related to this?
#19
I do not know. Let me test on my win 7 pc and see if I get the same results as you.
#20
OK, thanks
#21
I can confirm on win7 64bit I get the same results as you on. Must be a win7 bug.

Not sure how to fix it.
Will Have to wait and see if Gintaras has an ideas on how to fix it.
#22
This will fix it. Font variable needs to be a thread variable. My bad I completely forgot about that.
Code:
Copy      Help
,__Font-- f.Create("Courier New" 8 0)
,f.SetDialogFont(hDlg "3")
#23
@Kevin
Every time I use the above function(QMDRAGDROPINFO.GetText) I will have the following prompt in out, how to suppress the prompt message

Warning in <open ":434:">QMDRAGDROPINFO.GetText: Some STGMEDIUM members that have implicit or explicit constructor/destructor/copy functions are in union with other members. These functions will not be called. You may have to explicitly clear these members to avoid memory leak.    <help #IDP_DIR_OPT>?
#24
change code to this

Member function QMDRAGDROPINFO.GetText
Code:
Copy      Help
function! str&s [flags] ;;flags: 1 drag source must not delete text

;Extracts dropped text.
;Returns 1 if successful, 0 if failed.


s.fix(0)

int k=GetMod
sel(k) case [0,2] case else this.effect=DROPEFFECT_NONE; ret
if(flags&1) k=2

int i
for(i 0 this.formats.len) if(this.formats[i].cfFormat=CF_UNICODETEXT) break
if(i=this.formats.len) ret
#opt nowarnings 1
STGMEDIUM sm
this.dataObj.GetData(&this.formats[i] &sm); err ret

int gs=GlobalSize(sm.hGlobal)-2; if(gs<=0) ret
s.all(gs 2)
byte* m=GlobalLock(sm.hGlobal); if(!m) ret
memcpy s m s.len
GlobalUnlock sm.hGlobal
ReleaseStgMedium(&sm)
s.ansi
#opt nowarnings 0
sel k
,case 0 this.effect&DROPEFFECT_MOVE
,case 2 this.effect&DROPEFFECT_COPY

ret 1
#25
thank you so much


Forum Jump:


Users browsing this thread: 1 Guest(s)