ahk v1 中对ListBox的操作:增、删、改、上移、下移等操作。
#singleinstance force
title = ListBox 例子
gui,add,listbox,xm ym w100 r20 vLB choose1 gLBevent,电话|聊天|拍拖|表白|订婚|礼金|礼盒
gui,add,edit ,xm yp+250 w200 vEDT -background
gui,add,button,xm+110 ym w130 h20 gBTN1,总条数
gui,add,button,xp yp+20 wp hp gBTN2,增加
gui,add,button,xp yp+20 wp hp gBTN3,选择后插入一行
gui,add,button,xp yp+20 wp hp gBTN4,随机选择
gui,add,button,xp yp+20 wp hp gBTN5,删除选择行
gui,add,button,xp yp+20 wp hp gBTN6,全部删除
gui,add,button,xp yp+20 wp hp gBTN7,选择行号/名称
gui,add,button,xp yp+20 wp hp gBTN8,Height 间隔调整
gui,add,button,xp yp+20 wp hp gBTN20,重启
gui,add,button,xp yp+20 w65 hp glistboxUPDOWN vitemUP,上移
gui,add,button,xp+65 yp wp hp glistboxUPDOWN vitemDN,下移
gui,show,,% title
return
LBevent:
ifEqual, a_guievent, doubleclick, msgbox,64,info, % a_eventinfo,1 ;双击列表时获得该项的行号
return
BTN1:
sendmessage,0x18B,,,listbox1, % title ;获取总条目数
getCOUNT := errorlevel
guicontrol,,EDT,% "Total : " . errorlevel
return
BTN2:
sendmessage,0x180, , "添加项" . a_msec, listbox1, % title ;追加
gosub BTN1
return
BTN3:
gosub BTN7
sendmessage,0x181, LB_GETCURSEL, "插入项" . a_msec, listbox1, % title ;在选择一行后插入一行
gosub BTN1
return
BTN4:
gosub BTN1
random,NUM,0,% getCOUNT-1
sendmessage,0x186,NUM,,listbox1, % title ;用行号码选择某一项
return
BTN5:
gosub BTN7
sendmessage,0x182,LB_GETCURSEL-1,,listbox1, % title ;删除选中项
return
BTN6:
sendmessage,0x184,,,listbox1, % title ;全部删除
gosub BTN1
return
BTN7:
sendmessage,0x188,,,listbox1, % title ;所选项的行号
LB_GETCURSEL := errorlevel+1
controlget, getITEM, choice,, listbox1, % title ;所选项的名称
guicontrol,,EDT,% LB_GETCURSEL . "`," . getITEM
return
BTN8:
sendmessage,0x1A0,,15, listbox1, % title ;Height 间隔调整
guicontrol,+redraw,LB
return
listboxUPDOWN: ;移动项目
gui,submit,nohide
sendmessage,0x18B,,,listbox1, % title ;总条目数
LB_GETCOUNT := errorlevel
sendmessage,0x188,,,listbox1, % title ;获取选择项的行号
ifequal,a_guicontrol,itemUP,ifequal,errorlevel,0,return
ifequal,a_guicontrol,itemDN,ifequal,errorlevel,% LB_GETCOUNT-1,return
LB_GETCURSEL := errorlevel
sendmessage,0x182,LB_GETCURSEL,,listbox1, % title ; 删除项
sendmessage,0x181,LB_GETCURSEL + (a_guicontrol="itemDN" ? 1:-1),"" . LB, listbox1, % title ;增加
sendmessage,0x186,LB_GETCURSEL + (a_guicontrol="itemDN" ? 1:-1),,listbox1, % title ;选择
return
BTN20:
reload
guiescape:
guiclose:
exitapp