Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting A Selected ListBox Item in A Dialog
#1
I saw the discussion at: http://www.quickmacros.com/forum/showthr...p?tid=2557 regarding "Delete List Box Item in Dialog" but the mechanism was selecting the item to be deleted through a edit field. I wanted to select the item in the list box and then just delete it by hitting the delete key.

I accomplished this through a separate function with a delete key trigger with a filter function of the list box:

Function ListBoxDel
Trigger X //FF_ListBoxDel2     Help - how to add the trigger to the macro
Code:
Copy      Help
int hDlg = win("Sample Dialog" "#32770")
int hlb = id(6 hDlg);; the listbox id
str SelectedItemFromListBoxToDelete
_i=LB_SelectedItem(hlb)
if(_i>=0) SendMessage hlb LB_DELETESTRING _i 0

Function FF_ListBoxDel2
Code:
Copy      Help
;/
;Allows starting macro when mouse pointer is on certain control.

function# iid FILTER&f

if(!f.hwnd2) ret
if(!wintest(f.hwnd "CaseLog" "#32770")) ret ;;change window name and class
if(!childtest(f.hwnd2 "" "ListBox" f.hwnd)) ret ;;change control text and class
ret iid


This seems to work well. Is there any other way that is intrinsic to ListBox?
It's fine if this is the best way, though.

Stuart
#2
Subclass listbox and use WM_KEYDOWN message.
Function dlg_delete_lb_item
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4"
str lb3 lb4
lb3="one[]two[]three"
lb4=lb3
if(!ShowDialog("dlg_delete_lb_item" &dlg_delete_lb_item &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 0x200 10 16 96 48 ""
;4 ListBox 0x54230101 0x200 110 16 96 48 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030006 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,;subclass 2 listbox controls
,int hlb=id(3 hDlg)
,SetProp hlb "WndProc_lb_delete" SubclassWindow(hlb &WndProc_lb_delete)
,hlb=id(4 hDlg)
,SetProp hlb "WndProc_lb_delete" SubclassWindow(hlb &WndProc_lb_delete)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Function WndProc_lb_delete
Code:
Copy      Help
;/
function# hWnd message wParam lParam

sel message
,case WM_KEYDOWN
,sel wParam
,,case VK_DELETE
,,_i=LB_SelectedItem(hWnd)
,,if(_i>=0) SendMessage hWnd LB_DELETESTRING _i 0

ret CallWindowProcW(GetProp(hWnd "WndProc_lb_delete") hWnd message wParam lParam)


Forum Jump:


Users browsing this thread: 1 Guest(s)