added NSD_SetText, NSD_SetState, NSD_Check and NSD_Uncheck

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5548 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2008-02-22 17:01:44 +00:00
parent 340eec682c
commit 25c36be360
2 changed files with 103 additions and 0 deletions

View file

@ -35,6 +35,7 @@ code
<li><a href="#step-add">Adding Controls</a></li>
<li><a href="#step-state">Control State</a></li>
<li><a href="#step-notify">Real-time Notification</a></li>
<li><a href="#step-memory">Memory</a></li>
<li><a href="#helpful-macros">Helpful macros</a></li>
</ul>
</li>
@ -373,6 +374,76 @@ Section
SectionEnd</pre></blockquote>
<h3><a name="step-memory"></a>Memory</h3>
<p>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.</p>
<p>For clarity, we'll remove some of the notifications from the previous step.</p>
<blockquote><pre>!include nsDialogs.nsh
!include LogicLib.nsh
Name nsDialogs
OutFile nsDialogs.exe
XPStyle on
Var Dialog
Var Label
Var Text
<b>Var Text_State
Var Checkbox
Var Checkbox_State</b>
Page custom nsDialogsPage nsDialogsPageLeave
<b>Page license</b>
Page instfiles
<b>Function .onInit
StrCpy $Text_State "Type something here..."
FunctionEnd</b>
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% <b>12u $Text_State</b>
Pop $Text
<b>${NSD_CreateCheckbox} 0 30u 100% 10u "&amp;Something"
Pop $Checkbox
${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox
${EndIf}</b>
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $Text <b>$Text_State</b>
<b>${NSD_GetState} $Checkbox $Checkbox_State</b>
FunctionEnd
Section
DetailPrint "hello world"
SectionEnd</pre></blockquote>
<h3><a name="helpful-macros"></a>Helpful macros</h3>
<h4><a name="set-focus">Set focus to a control</h4>

View file

@ -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})"