Archive: Disable controls on custom page when checkbox checked


Disable controls on custom page when checkbox checked
I have created a custom page and as part of this page I want 2 textboxes to disable if a checkbox is checked and then enable if the checkbox is unchecked.

I have tried techniques described the user manual but have had no joy.

I want to do this in the nsDialogsPageCheckChange function.

Here is my installer script:

# This is a test of the MSSQL OLEDB plugin that can be used to connect to a SQL Server instance
# and execute commands and scripts

# The installer includes a custom page which allows you to enter the network name of the sql server,
# whether windows authentication is used or not and a username and password if required

# This custom page also includes a Skip button if the user does not know this details

Name "MSSQL:OLEDB Plugin Test"
outfile 'customtest.exe'

!include 'MUI.nsh'
!include 'nsDialogs.nsh'

Var Dialog
Var Label
Var Text
Var Check

!insertmacro MUI_LANGUAGE "English"
page custom CustomPage nsDialogsPageLeave

Function customPage
nsDialogs::Create /NOUNLOAD 1018

Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

; put controls onto the custom page
; parameters - x, y, width, height and text
${NSD_CreateLabel} 0 0 100% 20u "Enter the details for your SQL Server login below and then click Next to create an EmployerSafe database on the specified SQL Server."
Pop $Label

${NSD_CreateLabel} 0 20u 100% 20u "If you do not know these details, click on Skip and request that an IT administrator creates the Employersafe database using the supplied database creation script."
Pop $Label

${NSD_CreateLabel} 0 60u 30% 10u "SQL Server machine name:"
Pop $Label

${NSD_CreateText} 90u 60u 50% 13u ""
Pop $Text

${NSD_CreateLabel} 0 80u 30% 10u "Authentication details:"
Pop $Label

${NSD_CreateCheckBox} 90u 80u 70% 10u "Use Windows Authentication"
Pop $Check
${NSD_OnChange} $Check nsDialogsPageCheckChange

${NSD_CreateLabel} 0 95u 30% 10u "Username:"
Pop $Label

${NSD_CreateText} 90u 95u 50% 13u ""
Pop $Text

${NSD_CreateLabel} 0 110u 30% 10u "Password:"
Pop $Label

${NSD_CreateText} 90u 110u 50% 13u ""
Pop $Text

nsDialogs::Show

FunctionEnd

Function nsDialogsPageCheckChange
; Unchecked = 0, Checked = 1
${NSD_GetState} $Check $1

${If} $Check == 0
; enable username and password textboxes
${Else}
; disable username and password textboxes
${EndIf}
FunctionEnd

Function nsDialogsPageLeave

${NSD_GetText} $Text $0
MessageBox MB_OK "You typed:$\n$\n$0"

; Unchecked = 0, Checked = 1
${NSD_GetState} $Check $1
MessageBox MB_OK "$1"
FunctionEnd

Section ""
SectionEnd


SendMessage

http://nsis.sourceforge.net/Docs/Cha...html#4.9.14.10


How would I use this to enable/disable the text boxes on my custom page when the check box is checked or unchecked?


yeah, I'm not sure why he's pointing you to SendMessage :)

There's a few things to fix in your script first...

1. Make sure each control you interact with has its handle in a unique variable.


Var LabelUsername
Var TextUsername
Var LabelPassword
Var TextPassword

; ...

${NSD_CreateLabel} 0 95u 30% 10u "Username:"
Pop $LabelUsername

${NSD_CreateText} 90u 95u 50% 13u ""
Pop $TextUsername

${NSD_CreateLabel} 0 110u 30% 10u "Password:"
Pop $LabelPassword

${NSD_CreateText} 90u 110u 50% 13u ""
Pop $TextPassword


2. Checkboxes don't react to OnChange, only to OnClick (I don't know why)

${NSD_CreateCheckBox} 90u 80u 70% 10u "Use Windows Authentication"
Pop $Check
${NSD_OnClick} $Check nsDialogsPageCheckChange


3. The state of your $Check checkbox is output into $1, so that's what you need to test - not $Check


4. Use EnableWindow <handle> <0|1> to disable/enable the controls

${If} $1 == 0
; enable username and password textboxes
EnableWindow $LabelUsername 1
EnableWindow $TextUsername 1
EnableWindow $LabelPassword 1
EnableWindow $TextPassword 1
${Else}
; disable username and password textboxes
EnableWindow $LabelUsername 0
EnableWindow $TextUsername 0
EnableWindow $LabelPassword 0
EnableWindow $TextPassword 0
${EndIf}


With those changes, you should be all set :)

Thanks for the detailed reply and example.

I will try this later. :)

EDIT: This works perfectly! Thanks.