Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can WM_DROPFILES be used in a ListBox?
#7
You cant drag a QM item(macro,function,dialog ect.) from QM and drop onto a listbox.

That's why I showed you another way.
I have taken my example and your example and combined them and changed the functionality a little.
Instead of single left click to edit or run changed it to double left click so as it doesn't interfere with my addition.
I also made it so you can remove an item from the list box by using the delete key. It will delete whatever is selected.
Got rid of unneeded code as well.
Now simulates drag and drop of QM items on the edit control. Once and item is dropped onto the edit control it is added to the listbox automatically.
uses mac now to run or edit a QM item 
don't need to use keys  or use If i=0 ect ect

Function Favorites_Example2
Trigger Wff 0x4     Help - how to add the trigger to the macro
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CA0AC8 0x0 0 0 265 328 "Favorites_Example" "4"
;4 Edit 0x54030000 0x200 8 17 96 14 "" "Drop Item or Type Then click add"
;3 ListBox 0x5423050B 0x200 8 32 248 120 "Frequently Used:  (Run)"
;5 Button 0x54032000 0x0 105 17 48 14 "Find" "Finds the specified item"
;6 Button 0x54032000 0x0 153 17 48 14 "Add" "Adds the specified item"
;7 Button 0x54032000 0x0 201 17 48 14 "Remove" "Removes selected items"
;9 Edit 0x54030080 0x204 8 176 96 14 "" "Drop Item or Type Then click add"
;8 ListBox 0x54230509 0x204 8 192 248 120 "Edit Function:"
;10 Button 0x54032000 0x4 105 176 48 14 "Find" "Finds the specified item"
;11 Button 0x54032000 0x4 153 176 48 14 "Add" "Adds the specified item"
;12 Button 0x54032000 0x4 201 176 48 14 "Remove" "Removes selected items"
;13 Static 0x54000000 0x0 8 5 55 13 "Run Function:"
;14 Static 0x54000000 0x0 8 163 55 13 "Edit Function:"
;1 Button 0x54030001 0x4 23 116 48 14 "OK"
;2 Button 0x54030000 0x4 88 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "4 3 9 8"
str e4 lb3Fre e9 lb8Edi
lb3Fre="&Function100[]Function200"
lb8Edi="Function100[]&Function200"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hlb hedit i; str s ss
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"Drop Item here"
,SendMessage id(9 hDlg) EM_SETCUEBANNER TRUE @"Drop Item here"
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_VKEYTOITEM
,int lo=wParam&0xFFFF
,if lo=46;;if delete key in list box
,,if(GetDlgCtrlID(lParam)=3) but id(7 hDlg); else but id(12 hDlg)
ret
;messages2
if wParam=5 or wParam=6 or wParam=7
,hlb=id(3 hDlg)
,hedit=id(4 hDlg)
if wParam=10 or wParam=11 or wParam=12
,hlb=id(8 hDlg)
,hedit=id(9 hDlg)
sel wParam
,case IDOK
,case IDCANCEL
,case [5,10] ;;Find
,LB_SelectItem(hlb -1 2) ;;deselect all
,s.getwintext(hedit); if(!s.len) ret
,i=LB_FindItem(hlb s 0 1); if(i<0) i=LB_FindItem(hlb s); if(i<0) ret ;;find exact or partial
,LB_SelectItem(hlb i)    
,opt waitmsg 1
,act hlb
,case [6,11] ;;Add
,s.getwintext(hedit); if(!s.len) ret
,i=LB_FindItem(hlb s 0 1); if(i>=0 and mes("Already exists. Add anyway?" "" "YN?")!='Y') ret
,LB_Add hlb s
,LB_SelectItem(hlb -1 2) ;;deselect all
,LB_SelectString hlb s
,case [7,12] ;;Remove selected item or items
,ARRAY(int) ai
,if(!sub.LB_GetSelectedItems(hlb ai)) ret
,if(ai.len>1 and mes("Multiple Items Selected. Remove anyway?" "" "YN?")!='Y') ret
,for(i ai.len-1 -1 -1) SendMessage(hlb LB_DELETESTRING ai[i] 0)
,case [LBN_DBLCLK<<16|3,LBN_DBLCLK<<16|8];;run on double click,edit on double click
,i=LB_SelectedItem(lParam ss)
,if(GetDlgCtrlID(lParam)=3) mac ss; else mac+ ss
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|9]
,ifa- hDlg
,,int Bcid=iif(GetDlgCtrlID(lParam)=4 6 11)
,,but id(Bcid hDlg)
ret 1

#sub LB_GetSelectedItems
;/
function# hwnd [ARRAY(int)&ai] [ARRAY(str)&as]

;Gets selected items in a multisel listbox control.
;Returns number of selected items.

;hwnd - control handle.
;ai - array variable that receives indices of selected items. Optional, can be 0.
;as - array variable that receives text of selected items. Optional, can be 0.

;REMARKS
;The control must belong to current process. Use eg in dialog procedures.

if(&ai) ai=0
if(&as) as=0

int i n
n=SendMessage(hwnd LB_GETSELCOUNT 0 0); if(n<1) ret
if &ai or &as
,ARRAY(int) _ai; if(!&ai) &ai=_ai
,ai.create(n)
,n=SendMessage(hwnd LB_GETSELITEMS n &ai[0]); if(n<0) n=0
,if(n!ai.len) ai.redim(n)
,if &as
,,as.create(n)
,,for(i 0 n) LB_GetItemText(hwnd ai[i] as[i])
ret n


Messages In This Thread
RE: Can WM_DROPFILES be used in a ListBox? - by Kevin - 10-24-2020, 11:40 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)