开发者

Clearing the State of Fields in InstallOptions pages

开发者 https://www.devze.com 2023-04-09 16:49 出处:网络
I\'m working on an NSIS installer.One of the requirements is to allow the user to input some information multiple times for multiple different entries (essentially, it allows them to enter server info

I'm working on an NSIS installer. One of the requirements is to allow the user to input some information multiple times for multiple different entries (essentially, it allows them to enter server information for as many servers as they'd like). I'm currently recycling the pages by going to this page after my advanced options page:

Function RedirectPage
   ${If} $addtCheck <> 0 ; Was the checkbox checked?
      StrCpy $startedXml 1 ; make this "true"
       SendMessage $HWNDPARENT 0x408 -1 "" ; If so, go back
   ${Else}
      Abort
       ${EndIf}

FunctionEnd

addtCheck checks to see if the checkbox is ticked that recycles the page. If so this function causes the previous page to be displayed again. The problem is that the fields contain t开发者_如何学Gohe information that the user just entered. Now, what I want to do is to clear the State of all of the fields of the previous page before they go back to it. I have tried doing something like this,

!insertmacro MUI_INSTALLOPTIONS_WRITE "ioAdv.ini" "Field 2" "State" ""

but it doesn't seem to allow me to clear the state. I know of the SendMessage and GetDlgItem commands, but am unaware of any methods that allow me to use them to clear the text boxes, check boxes, and list boxes of contained in the InstallOptions INI file.

Anyone who can point me in the right direction, thanks. If you want to see any more of the script, let me know.


So you should have the controls in the ini like this:

  [Field 1]
  Type=Label
  Left=15
  Top=7
  Right=112
  Bottom=16
  Text=Text 1

then you can get a handle on the field like this:

ReadIniStr $0 $PLUGINSDIR\page_ini.ini "Field 1" "HWND"

So then you can use the SendMessage command with $0 like this:

SendMessage $0 ${WM_SETTEXT} 0 "STR:$InitialString"

This example should work on Text Boxes, for the other controls see the following: In the NSIS Installation Path under "Include" there is the File Winmessages.nsh with the Message Keys to use.

In my tests i found the key for setting checkboxes:

SendMessage $0 ${BM_SETCHECK} 0 "0"

For ListBoxes i found: (untested)

LB_RESETCONTENT
LB_SELECTSTRING

Hope that helps. PS: If you have any questions or critisism, please let me know.

PPS:

Alternatively, you could use the nsDialogs Macros with the HWND handle, i.e. for the Checkbox:

${NSD_Uncheck} $0

More Information to this Macros are here: nsDialogs Readme - Macros


You can use SendMessage to reset each control but then you have to handle different types of controls, it is much better to just reset the .ini:

page custom custdircreate_1
page directory dirpagecreate

Function custdircreate_1
SetOverwrite on
!insertmacro INSTALLOPTIONS_EXTRACT "ioAdv.ini"
SetOverwrite lastused
!insertmacro INSTALLOPTIONS_DISPLAY "ioAdv.ini"
FunctionEnd

Function dirpagecreate
SendMessage $HWNDPARENT 0x408 -1 ""
FunctionEnd

..or reset the state and keep everything else:

Function custdircreate_2
; INSTALLOPTIONS_EXTRACT was called in .onInit
!insertmacro INSTALLOPTIONS_READ $1 "ioAdv.ini" "Settings" "NumFields"
StrCpy $0 1
loop:
!insertmacro INSTALLOPTIONS_WRITE "ioAdv.ini" "Field $0" "State" ""
IntOp $0 $0 + 1
IntCmpU $0 $1 loop loop

!insertmacro INSTALLOPTIONS_DISPLAY "ioAdv.ini"
FunctionEnd

(This will reset link and button controls so filter those out of the loop if required)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号