如何从nsis中的组合框中删除所有元素

时间:2016-04-20 12:31:31

标签: combobox nsis

我想在点击nsis安装程序中的按钮

时删除组合框中的所有元素

1 个答案:

答案 0 :(得分:0)

nsDialogs没有Windows控件实现的每个功能的帮助程序宏,因此有时您需要咨询MSDN以查找有关自己发送哪条消息的信息。

!include nsDialogs.nsh
!include WinMessages.nsh
Page Custom MyPageCreate
Page InstFiles

Var MyComboHandle

Function ResetCombo
Pop $0
SendMessage $MyComboHandle ${CB_RESETCONTENT} 0 0
FunctionEnd

Function DeleteItemsButNotText
Pop $0
${NSD_GetText} $MyComboHandle $0
SendMessage $MyComboHandle ${CB_RESETCONTENT} 0 0
${NSD_SetText} $MyComboHandle $0
FunctionEnd
Function DeleteItemsButNotText_AlternateVersion
Pop $0
loop:
    SendMessage $MyComboHandle ${CB_DELETESTRING} 0 0 $0 ; This will also clear the text if it matches the item
    IntCmp $0 ${CB_ERR} "" loop loop
FunctionEnd

Function AddItems
Pop $0
${NSD_CB_AddString} $MyComboHandle "Foo"
${NSD_CB_AddString} $MyComboHandle "Bar"
SendMessage $MyComboHandle ${CB_SETCURSEL} 0 ""
FunctionEnd


Function MyPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateCombobox} 0 30u 100% 200u ""
Pop $MyComboHandle
Push ""
Call AddItems

${NSD_CreateButton} 0 50u 33% 12u "Reset"
Pop $0
${NSD_OnClick} $0 ResetCombo

${NSD_CreateButton} 33% 50u 33% 12u "Delete all items"
Pop $0
${NSD_OnClick} $0 DeleteItemsButNotText

${NSD_CreateButton} 66% 50u 33% 12u "Add items"
Pop $0
${NSD_OnClick} $0 AddItems

nsDialogs::Show
FunctionEnd