Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

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

Can anyone explain to me, why ${NSD_GetState} $Checkbox is not working ? I lost about 4 hours trying to find out what is wrong. I tried diffrent variants but in THIS script they are not working.

Actualy it is my first attempt to make a nsis installer, so I even dont know where should I look for mistake or I just dont understand the logic of this language.

From Russia with love :) And sorry for my bad english

!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}ContribGraphicsHeaderHEADER2.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_ICON "${NSISDIR}ContribGraphicsIconsmedia-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 $6 $HWNDPARENT 1
        EnableWindow $6 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 $0
    StrCpy $DestDrive "$0"
    GetDlgItem $6 $HWNDPARENT 1
    EnableWindow $6 1
FunctionEnd

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

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

Functionend

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

Section "" main


InitPluginsDir

File /oname=$PLUGINSDIRsyslinux.cfg  "${NSISDIR}pluginssyslinux.cfg"
File /oname=$PLUGINSDIRsyslinux.exe  "${NSISDIR}pluginssyslinux.exe"

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


StrCpy $R0 $DestDrive -1


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



nsExec::Exec '$PLUGINSDIRsyslinux.exe -maf -d bootsyslinux $R0' 


;SendMessage $Checkbox ${BM_GETSTATE} 0 0 $0
;${If} $0 != 0

;  MessageBox MB_OK checked!

;${EndIf}

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


CopyFiles $PLUGINSDIRsyslinux.cfg  "$R0syslinux.cfg"


SectionEnd
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is so much unrelated code in your example that it is a bit hard to understand what you really want to do.

If you want to retrieve the state of a checkbox on another page then you must save the state because the checkbox control is destroyed when you leave the page.

!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 $0

${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 $0

${NSD_CreateLabel} 0 0 100% 160 CheckboxState=$CheckboxState
Pop $0

nsDialogs::Show
FunctionEnd

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...