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

How to delete all the elements from the combo box in nsis

我想通过单击 nsis 安装程序中的按钮从组合框中删除所有元素

nsDialogs 并没有为 Windows 控件实现的每个功能提供辅助宏,因此有时您必须参考 MSDN 才能找到有关要发送给自己的消息的信息。

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

Var MyComboHandle

Function ResetCombo
Pop [=10=]
SendMessage $MyComboHandle ${CB_RESETCONTENT} 0 0
FunctionEnd

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

Function AddItems
Pop [=10=]
${NSD_CB_AddString} $MyComboHandle "Foo"
${NSD_CB_AddString} $MyComboHandle "Bar"
SendMessage $MyComboHandle ${CB_SETCURSEL} 0 ""
FunctionEnd


Function MyPageCreate
nsDialogs::Create 1018
Pop [=10=]

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

${NSD_CreateButton} 0 50u 33% 12u "Reset"
Pop [=10=]
${NSD_OnClick} [=10=] ResetCombo

${NSD_CreateButton} 33% 50u 33% 12u "Delete all items"
Pop [=10=]
${NSD_OnClick} [=10=] DeleteItemsButNotText

${NSD_CreateButton} 66% 50u 33% 12u "Add items"
Pop [=10=]
${NSD_OnClick} [=10=] AddItems

nsDialogs::Show
FunctionEnd