NSIS listbox使用技巧

1) 删除节点

 

${NSD_LB_DelString} 存在bug,作者没有仔细研究windows message的要求。

写成了这个样子

SendMessage ${CONTROL} ${LB_DELETESTRING} 0 `STR:${STRING}`   

实际上,微软的LB_DELETESTRING需要的是item的需要,而不是字符串的内容。

所以,重写了一个,先查询index,然后删除。

 

!macro __GOOD_NSD_LB_DelString CONTROL STRING Push $1 SendMessage ${CONTROL} ${LB_FINDSTRINGEXACT} -1 'STR:${STRING}' $1 SendMessage ${CONTROL} ${LB_DELETESTRING} $1 0 Pop $1 !macroend !define GOOD_NSD_LB_DelString `!insertmacro __GOOD_NSD_LB_DelString`   

使用方法和NSD_LB_DelString一样。

${NSD_LB_DelString} listbox_HWND string

 

2) 支持多选和排序

默认的listbox不支持多选和自动排序,只好自己做了一个。

!Define NSD_CreateSortedListBox "nsDialogs::CreateControl ${__NSD_ListBox_CLASS} ${__NSD_ListBox_STYLE}|${LBS_SORT}|${LBS_MULTIPLESEL} ${__NSD_ListBox_EXSTYLE}"

使用和标准的一样

${NSD_CreateSortedListBox} 0 10% 15% 65% ""

 

4) 支持多选,如果需要支持用button在两个listbox之间移动选中项,可以不button的相应函数写成这样

 

 

Function OnClick_MoveTO #get maximum of selected items SendMessage $Listbox_FROM ${LB_GETCOUNT} $0 $0 $itemCount #allocate memory for $itemCount integers IntOp $0 $itemCount * 4 System::Alloc $0 Pop $address #place indices of selected items in the allocated memory SendMessage $Listbox_FROM ${LB_GETSELITEMS} $itemCount $address $selItemCount ${If} $selItemCount > 0 ; Calculate the address of last item IntOp $5 $selItemCount - 1 IntOp $5 $5 * 4 IntOp $address $address + $5 ; Delete will change the item idex, so delete from the last selection to first one. ${For} $R1 1 $selItemCount #get current index System::Call "*$address(i .r0)" System::Call user32::SendMessage(i$Listbox_FROM,i${LB_GETTEXT},i$0,t.r1) ${NSD_LB_AddString} $Listbox_TO "$1" SendMessage $Listbox_FROM ${LB_DELETESTRING} $0 `STR:$1` #move to next index IntOp $address $address - 4 ${Next} ${Endif} System::Free $address FunctionEnd

你可能感兴趣的:(NSIS listbox使用技巧)