Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamically create SysListView
#4
try this should cover all 6 requests
added additional functionality
enter key also returns selected item idex
double left mouse click on item also does the same

Function DynamicLV
Code:
Copy      Help
;/
function# str'text
out
str dd=
F
;BEGIN DIALOG
;0 "" 0x90080AC8 0x0 0 0 184 108 "Dialog"
;3 SysListView32 0x5403C04D 0x204 0 0 184 108 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C00 "*" "" "" ""

int iii= ShowDialog(dd &sub.DlgProc 0)
ret iii

#sub DlgProc v
function# hDlg message wParam lParam

int hsys32=id(3 hDlg)
sel message
,case WM_INITDIALOG
,__Font- f.CreateNew(hsys32 "Microsoft YaHei Mono" 11) ;;change this
,f.SetDialogFont(hDlg "3")    
,int es=LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP|LVS_EX_GRIDLINES
,SendMessage hsys32 LVM_SETEXTENDEDLISTVIEWSTYLE es es
,TO_LvAddCol hsys32 0 "" -90
,TO_LvAddCol hsys32 1 "" -10
;,Fill-in values to sys32
,int n=numlines(text)
,for int'i 0 n
,,_s.getl(text i)
,,TO_LvAdd hsys32 i 0 0 _s i+1
,RECT r.left=LVIR_BOUNDS; SendMessage(hsys32 LVM_GETITEMRECT 0 &r)
,int xy=SendMessage(hsys32 LVM_APPROXIMATEVIEWRECT n -1|-1)
,int width = xy & 0x0000FFFF
,int hh = xy>>16&0x0000FFFF
,siz width+4 hh hsys32
,siz width+11 hh-r.bottom+8 hDlg
,sub.LvSelect hsys32 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3    
ret
;messages2
sel wParam
,case IDOK
,int ii=SendDlgItemMessage(hDlg 3 LVM_GETNEXTITEM -1 LVNI_SELECTED)
,DT_EndDialog(hDlg ii)
,case IDCANCEL
,DT_EndDialog(hDlg 0)
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,sel nh.code
,,case LVN_KEYDOWN
,,NMLVKEYDOWN* lvk=+nh
,,for i 0 numlines(text)
,,,_s.getl(text i)
,,,if(_s[0] = lvk.wVKey)
,,,,DT_EndDialog(hDlg i)
,,,,break
,,case NM_DBLCLK;;on double left click of listview item
,,;lvSelect
,,i=SendDlgItemMessage(hDlg 3 LVM_GETNEXTITEM -1 LVNI_SELECTED)
,,DT_EndDialog(hDlg i)

#sub LvSelect
function hlv item [flags] ;;flags: 1 don't deselect previous, 2 don't set focus, 4 ensure visible, 8 deselect

;Selects listview item.
;To select none, use item -1.
;To select all, use item -1 and flag 8.
;Note that listview controls with LVS_SINGLESEL style can have max 1 item selected.

LVITEMW li.stateMask=LVIS_FOCUSED|LVIS_SELECTED
if(item>=0)
,if(flags&9=0) SendMessage hlv LVM_SETITEMSTATE -1 &li
,if(flags&8=0) li.state=LVIS_SELECTED; if(flags&2=0) li.state|LVIS_FOCUSED
,SendMessage hlv LVM_SETITEMSTATE item &li
,if(flags&4) SendMessage hlv LVM_ENSUREVISIBLE item 0
else
,if(flags&8) li.state=LVIS_SELECTED
,SendMessage hlv LVM_SETITEMSTATE -1 &li

added functionality if alt+f4 is used to close dialog macro will end
Macro Macro9
Code:
Copy      Help
_s=
;A  I'm in the line 1
;B  I'm in the line 2
;C  I'm in the line 3
;D  I'm in the line 4
;E  I'm in the line 5

int i=DynamicLV(_s)

if i=1000
,ret;; end if alt+f4 was used to closed dialog
out i    
str ss
ss.getl(_s i)
out ss


Messages In This Thread
Dynamically create SysListView - by Davider - 08-18-2022, 03:15 AM
RE: Dynamically create SysListView - by Davider - 08-18-2022, 09:05 AM
RE: Dynamically create SysListView - by Gintaras - 08-18-2022, 09:19 AM
RE: Dynamically create SysListView - by Kevin - 08-19-2022, 11:31 PM
RE: Dynamically create SysListView - by Davider - 08-20-2022, 12:49 AM
RE: Dynamically create SysListView - by Kevin - 08-20-2022, 03:44 AM
RE: Dynamically create SysListView - by Davider - 08-20-2022, 10:28 AM
RE: Dynamically create SysListView - by Kevin - 08-20-2022, 11:51 AM
RE: Dynamically create SysListView - by Davider - 08-20-2022, 12:10 PM
RE: Dynamically create SysListView - by Davider - 08-20-2022, 11:13 PM
RE: Dynamically create SysListView - by Gintaras - 08-21-2022, 11:35 AM
RE: Dynamically create SysListView - by Davider - 08-21-2022, 12:41 PM
RE: Dynamically create SysListView - by Davider - 08-21-2022, 09:41 PM
RE: Dynamically create SysListView - by Gintaras - 08-22-2022, 11:45 AM
RE: Dynamically create SysListView - by Davider - 08-22-2022, 12:42 PM
RE: Dynamically create SysListView - by Gintaras - 08-22-2022, 01:11 PM
RE: Dynamically create SysListView - by Davider - 08-22-2022, 02:08 PM
RE: Dynamically create SysListView - by Kevin - 08-23-2022, 03:30 AM
RE: Dynamically create SysListView - by Davider - 08-23-2022, 09:40 AM
RE: Dynamically create SysListView - by Davider - 11-04-2022, 02:05 AM
RE: Dynamically create SysListView - by Kevin - 11-04-2022, 05:31 AM
RE: Dynamically create SysListView - by Davider - 11-04-2022, 05:57 AM
RE: Dynamically create SysListView - by Kevin - 11-04-2022, 02:45 PM
RE: Dynamically create SysListView - by Davider - 11-07-2022, 12:19 PM
RE: Dynamically create SysListView - by Kevin - 11-17-2022, 01:37 AM
RE: Dynamically create SysListView - by Davider - 11-25-2022, 04:34 AM
RE: Dynamically create SysListView - by Kevin - 11-27-2022, 02:19 AM
RE: Dynamically create SysListView - by Davider - 11-27-2022, 02:44 AM
RE: Dynamically create SysListView - by Davider - 12-02-2022, 02:24 AM
RE: Dynamically create SysListView - by Davider - 12-02-2022, 12:31 PM
RE: Dynamically create SysListView - by Kevin - 12-02-2022, 05:42 PM
RE: Dynamically create SysListView - by Davider - 12-02-2022, 09:14 PM
RE: Dynamically create SysListView - by Kevin - 12-10-2022, 03:09 AM
RE: Dynamically create SysListView - by Davider - 12-10-2022, 10:47 PM
RE: Dynamically create SysListView - by Davider - 03-26-2023, 02:16 AM
RE: Dynamically create SysListView - by Kevin - 03-27-2023, 01:29 AM
RE: Dynamically create SysListView - by Davider - 03-27-2023, 02:26 AM

Forum Jump:


Users browsing this thread: 16 Guest(s)