当我期望“TEST”时,DropList 被设置为“TEST A”。
NSD_CB_SelectString 是否包含?
Name test
OutFile tester.exe
!include nsDialogs.nsh
XPStyle on
Page custom MyPage
Page instfiles
Function MyPage
nsDialogs::Create 1018
Pop $0
${If} $0 == error
MessageBox MB_OK "Error"
Abort
${EndIf}
VAR /GLOBAL droplist
${NSD_CreateDropList} 0% 0 25% 12u ''
Pop $DropList
${NSD_ONCHANGE} $DropList DropList_OnChange
${NSD_CB_AddString} $DropList "TEST A"
${NSD_CB_AddString} $DropList "TEST"
${NSD_CB_AddString} $DropList "TEST1"
${NSD_CB_SelectString} $DropList "TEST"
nsDialogs::Show
FunctionEnd
Function DropList_OnChange
${NSD_GetText} $DropList $0
MessageBox MB_OK "$0"
FunctionEnd
Section ''
SectionEnd
如果我更改 NSD_CB_SelectString = "TEST1" 那么它可以正常工作。
NSD_CB_SelectString
可以正常工作,因为它
搜索组合框列表中以开头的项目 指定字符串中的字符。
阅读 https://learn.microsoft.com/en-us/windows/win32/controls/cb-selectstring 了解详细信息。
这是适合您任务的 nsDialogs 风格宏:
!define NSD_CB_SelectStringExact "!insertmacro _NSD_CB_SelectStringExact "
!macro _NSD_CB_SelectStringExact CONTROL STRING
!insertmacro _LOGICLIB_TEMP
SendMessage ${CONTROL} ${CB_FINDSTRINGEXACT} -1 `STR:${STRING}` $_LOGICLIB_TEMP
StrCmp $_LOGICLIB_TEMP -1 +2
SendMessage ${CONTROL} ${CB_SETCURSEL} $_LOGICLIB_TEMP 0
!macroend
将此宏添加到您的 .nsi 脚本或(最好)到头文件(例如 nsDialogsEx.nsh)中。
然后在脚本中将
${NSD_CB_SelectString} $DropList "TEST"
字符串替换为 ${NSD_CB_SelectStringExact} $DropList "TEST"