在 NSIS 安装程序中单击返回时记住复选框状态

Remember check box state when click back during NSIS installer

我的一个客户安装程序页面上有一个复选框

${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $SvcCheckBox
CreateFont [=10=] "$(^Font)" "10"
SendMessage $SvcCheckBox ${WM_SETFONT} [=10=] 1
GetFunctionAddress [=10=] OnCheckbox
nsDialogs::OnClick $SvcCheckBox [=10=]

如果用户返回此页面,我想记住这一点。

我已经使用下面的代码进行了尝试

${NSD_OnBack} "pageLeave"

FunctionEnd


Function pageLeave
    ${NSD_GetState} $SvcCheckBoxState $SvcCheckBox
FunctionEnd

但是,如果用户取消选中该框,转到下一页,返回到该页面,则再次选中该复选框。我需要它保持未选中状态。

如何在页面加载时实现 pageLeave 复选框状态?

您需要在创建页面时初始化复选框状态。您不需要 On* 处理程序,除非您想在复选框更改时更新页面上的其他内容。

!include nsDialogs.nsh

Var CheckboxState
Var hCheckbox

Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set initial/default state
FunctionEnd

Page Components
Page Custom MyPageCreate MyPageLeave
Page Components
Page InstFiles

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

${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $hCheckbox
${NSD_SetState} $hCheckbox $CheckboxState

nsDialogs::Show
FunctionEnd

Function MyPageLeave
${NSD_GetState} $hCheckbox $CheckboxState
FunctionEnd

Section
DetailPrint State=$CheckboxState
SectionEnd