Archive: How to reset the password field on a page


How to reset the password field on a page
Hi,
I am trying to take the installation name and password as input on an NSIS page. But when the user enters an invalid installation name, I want to reset the password field to blank after displaying the warning message.
I have tried:
1. DeleteINIStr with FlushINI
2. ReadINIStr/GetDlgItem with SendMessage

but nothing seems to reset that field on the page to blank.

Any help would be greatly appreciated.

Thanks
DeEpAk


Option 2 should work. What's the exact code you've used?


ReadINIStr $1 "$PLUGINSDIR\pick_installation.ini" "Field 3" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:"

I also tried using GetDlgItem and but dont know how to get the item_id for this password field. If I use GetDlgItem with Item_ids 1,2,3,etc. I can blank out the text for 'next', 'cancel' and 'back' buttons.

Thanks
DeEpAk


That should work assuming it's placed in the leave function and that Abort is called right after it. Attach a complete minimal example to give it some context.


Sure,
Here is the page declaration:
Page custom PickInstallation validateinstallation

now the functions:
Function PickInstallation
!insertmacro LogFunctionBegin "PickInstallation"
!insertmacro MUI_HEADER_TEXT "Application Configuration" "Choose a unique installation name."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "pick_installation.ini"
!insertmacro LogFunctionEnd "PickInstallation"
FunctionEnd


Function ValidateInstallation
!insertmacro LogFunctionBegin "ValidateInstallation"
IfSilent +3 +1
ReadINIStr $INSTALLATION "$PLUGINSDIR\pick_installation.ini" "Field 1" "State"
${LogText} "USER INPUT-> Installation name: $INSTALLATION"
StrCmp $INSTALLATION "" 0 CONTINUE1
ReadINIStr $1 "$PLUGINSDIR\pick_installation.ini" "Field 3" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:"
!insertmacro LogAndAbort "Please enter a unique installation name"
CONTINUE1:
................
................

And the defition for LogAndAbort:

!macro LogAndAbort message
${LogText} "Error : ${message}"
IfSilent +2 +1
MessageBox MB_OK|MB_ICONEXCLAMATION "${message}"
Abort
!macroend


Thanks
DeEpAk


Did you include WinMessages.nsh? What about the INI file? Are you sure the right field is no. 3?

BTW, ValidateInstallation will never be called for silent installers, you can skip IfSilent. In fact, no page functions are called for silent installers. The jump is also malformed because +3 will not jump over $[LogText} which is a macro insertion that can add more than one command.


Yes Kichik,
I did include WinMessages.nsh and of course, the INI file as all other fields displayed on the page are picked from this INI itself.
Btw, can you help me know the item_id of this field. Its type is "PASSWORD".

DeEpAk


The item id is 1200 + field number - 1 as documented in the InstallOptions readme.

As for the problem itself, attach a complete minimal example reproducing it. I can't see the problem with the current level of details. It all seems like it should work.


Hey,
That works.
I used:
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 1202
SendMessage $1 ${WM_SETTEXT} 0 "STR:"

So looks like ReadINIStr wasnt doing the job that GetDlgItem did.

Thanks a ton Kichki :-)
DeEpAk