${NSD_CreateListBox} 用于创建列表框
但是创建出来的列表框是无法多选和列表本身会自动排序
所以我们可以自己定义一个
创建多选和排序列表
;Usage:
${NSD_NSD_CreateSortedListBox} X Y 宽 高 ""
!Define NSD_CreateSortedListBox "nsDialogs::CreateControl ${__NSD_ListBox_CLASS} ${__NSD_ListBox_STYLE}|${LBS_SORT}|${LB}
由于可以多选,删除所选的列表项时我们再写一个删除宏${NSD_LB_DelSelectString}
/*
删除所选的列表项目
Usage:
${NSD_LB_DelSelectString} CONTROL
*/
Var D8_itemCount
Var D8_address
Var D8_selItemCount
!macro __NSD_LB_DelSelectString CONTROL
#获得项目数$ItemCount
SendMessage ${CONTROL} ${LB_GETCOUNT} $0 $0 $D8_itemCount
#分配项目数$ItemCount内存
IntOp $0 $D8_itemCount * 4
System::Alloc $0
Pop $D8_address
#给选定的项目分配内存
SendMessage ${CONTROL} ${LB_GETSELITEMS} $D8_itemCount $D8_address $D8_selItemCount
${If} $D8_selItemCount > 0
;计算最后一项目的地址
IntOp $5 $D8_selItemCount - 1
IntOp $5 $5 * 4
IntOp $D8_address $D8_address + $5
;删除选定index项目,所以从最后项目删除到第一个项目。
${For} $R1 1 $D8_selItemCount
#获取选定项目index
System::Call "*$D8_address(i .r0)"
System::Call user32::SendMessage(i${CONTROL},i${LB_GETTEXT},i$0,t.r1)
SendMessage ${CONTROL} ${LB_DELETESTRING} $0 `STR:$1`
#移动到下一个index
IntOp $D8_address $D8_address - 4
${Next}
${Endif}
System::Free $D8_address
!macroend
最后我们的实现的脚本
!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
!include "nsDialogs_LB_DelSelectString.nsh"
Caption "创建多选和排序listbox列表控件及操作"
OutFile "yhxs3344.exe"
BrandingText "www.yhxs3344.net"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
Page Custom pre
var dialog
Var ListBox
Var button
Var hwnd
Function pre
nsDialogs::Create 1018
Pop $dialog
${NSD_CreateSortedListBox} 0 0 50% 100% ""
Pop $ListBox
;SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:永恒心锁"
${NSD_LB_AddString} $ListBox "永恒心锁"
${NSD_LB_AddString} $ListBox "yhxs3344"
${NSD_LB_AddString} $ListBox "yhxs3344.Net"
${NSD_LB_AddString} $ListBox "永恒心锁"
${NSD_LB_AddString} $ListBox "永恒心锁"
${NSD_LB_AddString} $ListBox "永恒心锁"
;选择列表框(list box)中的字符串(仅一列)
;${NSD_LB_SelectString} $ListBox "永恒心锁"
${NSD_CreateText} 55% 0 100% 12u "永恒心锁"
Pop $hwnd
${NSD_CreateButton} 55% 15% 40% 13u "删除列表中上文本框文字"
Pop $button
${NSD_OnClick} $button Button1
${NSD_CreateButton} 55% 30% 40% 13u "添加上文本框文字到列表中"
Pop $button
${NSD_OnClick} $button Button2
${NSD_CreateButton} 55% 45% 40% 13u "删除所选列表"
Pop $button
${NSD_OnClick} $button Button3
nsDialogs::Show
FunctionEnd
;删除列表文字
Function Button1
${NSD_GetText} $hwnd $0
MessageBox MB_OK '删除【$0】?'
;修正NSD_LB_DelString
${NSD_LB_DelString} $ListBox "$0"
FunctionEnd
;添加列表文字
Function Button2
${NSD_GetText} $hwnd $0
MessageBox MB_OK '添加【$0】?'
${NSD_LB_AddString} $ListBox "$0"
FunctionEnd
;删除所选列表项
Function Button3
${NSD_LB_DElSelectString} $ListBox
FunctionEnd
Section -yhxs3344.Net
SectionEnd
THE END
暂无评论内容