无法理解为什么 ${NSD_GetState} $Checkbox 不起作用

Cant understand why ${NSD_GetState} $Checkbox is not working

谁能给我解释一下,为什么 ${NSD_GetState} $Checkbox 不起作用? 我花了大约 4 个小时试图找出问题所在。我尝试了不同的变体,但在这个脚本中它们不起作用。

其实我是第一次尝试做一个nsis安装器,所以我什至不知道应该在哪里找错误或者我只是不明白这门语言的逻辑。

来自俄罗斯的爱:) 对不起我的英语不好

!define NAME "Simple LiveUSB installer"
!define FILENAME "USB"
!define VERSION "v0.1"

Name "${NAME} ${VERSION}"
OutFile "${FILENAME}.exe"

SetCompressor LZMA
ShowInstDetails hide
XPStyle on

!include MUI2.nsh
!include FileFunc.nsh
!include nsDialogs.nsh
;!include LogicLib.nsh

!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\HEADER2.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\media-floppy.ico"


Page custom drivePage
Page custom Var123

!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "Russian"
LangString DrivePage_Title ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Title2 ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text2 ${LANG_RUSSIAN} "Format"
LangString DrivePage_Input ${LANG_RUSSIAN} "Choose"



Var Label
Var Label2
Var Checkbox
;Var Checkbox_State
Var DestDriveHW
Var DestDrive

# Functions #######################################

Function drivePage

    !insertmacro MUI_HEADER_TEXT $(DrivePage_Title) $(DrivePage_Title2)

    nsDialogs::Create 1018

    ${If} $DestDrive == ""
        GetDlgItem  $HWNDPARENT 1
        EnableWindow  0
    ${EndIf}

    ${NSD_CreateLabel} 0 0 100% 160 $(DrivePage_Text)
    Pop $Label

    ${NSD_CreateLabel} 10 182 100% 15 $(DrivePage_Input)
    Pop $Label2

    ${NSD_CreateDroplist} 10 200 13% 20 ""
    Pop $DestDriveHw

    ${NSD_OnChange} $DestDriveHw db_select.onchange
    ${GetDrives} "FDD" driveListFiller

    ${If} $DestDrive != ""
        ${NSD_CB_SelectString} $DestDriveHw $DestDrive
    ${EndIf}

    ${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
    Pop $Checkbox

    ${If} $Checkbox_State == ${BST_CHECKED}
        ${NSD_Check} $Checkbox_State
    ${EndIf}

    nsDialogs::Show
FunctionEnd


Function db_select.onchange
    Pop $DestDriveHw

    ${NSD_GetText} $DestDriveHw [=11=]
    StrCpy $DestDrive "[=11=]"
    GetDlgItem  $HWNDPARENT 1
    EnableWindow  1
FunctionEnd

Function driveListFiller
    SendMessage $DestDriveHw ${CB_ADDSTRING} 0 "STR:"
    Push 1
FunctionEnd

Function Var123
Pop $Checkbox
MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
${NSD_GetState} $Checkbox [=11=]
${If} [=11=] <> 0
    MessageBox mb_ok "Custom checkbox was checked... N=[=11=]"
${EndIf}
${If} [=11=] == 0
    MessageBox mb_ok "Custom checkbox ZERO... N=[=11=]"
${EndIf}

Functionend

# Section #######################################

Section "" main


InitPluginsDir

File /oname=$PLUGINSDIR\syslinux.cfg  "${NSISDIR}\plugins\syslinux.cfg"
File /oname=$PLUGINSDIR\syslinux.exe  "${NSISDIR}\plugins\syslinux.exe"

File /oname=$PLUGINSDIR\nsExec.dll  "${NSISDIR}\plugins\nsExec.dll"


StrCpy $R0 $DestDrive -1


;ExpandEnvStrings [=11=] %COMSPEC%
;nsExec::Exec '"[=11=]" /c echo. | format $R0 /q /x /v:LiveUSB /fs:fat32'



nsExec::Exec '$PLUGINSDIR\syslinux.exe -maf -d boot\syslinux $R0' 


;SendMessage $Checkbox ${BM_GETSTATE} 0 0 [=11=]
;${If} [=11=] != 0

;  MessageBox MB_OK checked!

;${EndIf}

;Pop $Checkbox
;MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
;${NSD_GetState} $Checkbox [=11=]
;${If} [=11=] <> 0
;    MessageBox mb_ok "Custom checkbox was checked... N=[=11=]"
;${EndIf}


CopyFiles $PLUGINSDIR\syslinux.cfg  "$R0\syslinux.cfg"


SectionEnd

你的例子中有太多不相关的代码,有点难以理解你真正想做什么。

如果您想在另一个页面上检索复选框的状态,则必须保存该状态,因为当您离开该页面时,复选框控件会被销毁。

!include nsDialogs.nsh

Var hwndCheckbox
Var CheckboxState
Page Custom myPageWithCombobox myPageWithComboboxLeaveCallback
Page Custom myPageWithComboState



Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set the initial state. This is optional but useful if you use $CheckboxState in a section when the installer is silent
FunctionEnd

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

${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
Pop $hwndCheckbox
${NSD_SetState} $hwndCheckbox $CheckboxState ; Reuse the existing state so it is correct when the back button is used

nsDialogs::Show
FunctionEnd

Function myPageWithComboboxLeaveCallback
${NSD_GetState} $hwndCheckbox $CheckboxState ; Save the state so we can retrieve it on the next page
FunctionEnd



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

${NSD_CreateLabel} 0 0 100% 160 CheckboxState=$CheckboxState
Pop [=10=]

nsDialogs::Show
FunctionEnd