diff --git a/Contrib/nsDialogs/Readme.html b/Contrib/nsDialogs/Readme.html index e69dcf79..d21a4855 100644 --- a/Contrib/nsDialogs/Readme.html +++ b/Contrib/nsDialogs/Readme.html @@ -35,6 +35,7 @@ code
  • Adding Controls
  • Control State
  • Real-time Notification
  • +
  • Memory
  • Helpful macros
  • @@ -373,6 +374,76 @@ Section SectionEnd +

    Memory

    + +

    So far we have a page that has some basic input controls. But what happens when the user goes to the next page and comes back? With the current code, the user's input will not be remembered. To remember, we'll use the already present leave callback function to store the user's choice in variables and pass these values when creating the controls the next time. For a better example, we'll also add a checkbox to the page and use ${NSD_GetState} and ${NSD_SetState} to get and set its state.

    + +

    For clarity, we'll remove some of the notifications from the previous step.

    + +
    !include nsDialogs.nsh
    +!include LogicLib.nsh
    +
    +Name nsDialogs
    +OutFile nsDialogs.exe
    +
    +XPStyle on
    +
    +Var Dialog
    +Var Label
    +Var Text
    +Var Text_State
    +Var Checkbox
    +Var Checkbox_State
    +
    +Page custom nsDialogsPage nsDialogsPageLeave
    +Page license
    +Page instfiles
    +
    +Function .onInit
    +
    +	StrCpy $Text_State "Type something here..."
    +
    +FunctionEnd
    +
    +Function nsDialogsPage
    +
    +	nsDialogs::Create /NOUNLOAD 1018
    +	Pop $Dialog
    +
    +	${If} $Dialog == error
    +		Abort
    +	${EndIf}
    +
    +	${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
    +	Pop $Label
    +
    +	${NSD_CreateText} 0 13u 100% 12u $Text_State
    +	Pop $Text
    +
    +	${NSD_CreateCheckbox} 0 30u 100% 10u "&Something"
    +	Pop $Checkbox
    +
    +	${If} $Checkbox_State == ${BST_CHECKED}
    +		${NSD_Check} $Checkbox
    +	${EndIf}
    +
    +	nsDialogs::Show
    +
    +FunctionEnd
    +
    +Function nsDialogsPageLeave
    +
    +	${NSD_GetText} $Text $Text_State
    +	${NSD_GetState} $Checkbox $Checkbox_State
    +
    +FunctionEnd
    +
    +Section
    +
    +	DetailPrint "hello world"
    +
    +SectionEnd
    +

    Helpful macros

    Set focus to a control

    diff --git a/Contrib/nsDialogs/nsDialogs.nsh b/Contrib/nsDialogs/nsDialogs.nsh index 624a0fcf..43bf9750 100644 --- a/Contrib/nsDialogs/nsDialogs.nsh +++ b/Contrib/nsDialogs/nsDialogs.nsh @@ -305,6 +305,14 @@ Header file for creating custom installer pages with nsDialogs !define NSD_GetText `!insertmacro __NSD_GetText` +!macro __NSD_SetText CONTROL TEXT + + SendMessage $CONTROL ${WM_SETTEXT} 0 `STR:${TEXT}` + +!macroend + +!define NSD_SetText `!insertmacro __NSD_SetText` + !macro __NSD_GetState CONTROL VAR SendMessage ${CONTROL} ${BM_GETCHECK} 0 0 ${VAR} @@ -313,6 +321,30 @@ Header file for creating custom installer pages with nsDialogs !define NSD_GetState `!insertmacro __NSD_GetState` +!macro __NSD_SetState CONTROL STATE + + SendMessage ${CONTROL} ${BM_SETCHECK} ${STATE} 0 + +!macroend + +!define NSD_SetState `!insertmacro __NSD_SetState` + +!macro __NSD_Check CONTROL + + ${NSD_SetState} ${CONTROL} ${BST_CHECKED} + +!macroend + +!define NSD_Check `!insertmacro __NSD_Check` + +!macro __NSD_Uncheck CONTROL + + ${NSD_SetState} ${CONTROL} ${BST_UNCHECKED} + +!macroend + +!define NSD_Uncheck `!insertmacro __NSD_Uncheck` + !macro __NSD_SetFocus HWND System::Call "user32::SetFocus(i${HWND})"