清除 InstallOptions 页面中的字段状态

发布于 2024-12-07 00:39:01 字数 773 浏览 0 评论 0原文

我正在开发 NSIS 安装程序。要求之一是允许用户为多个不同的条目多次输入某些信息(本质上,它允许他们为任意数量的服务器输入服务器信息)。我目前正在通过在高级选项页面之后转到此页面来回收页面:

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 检查是否选中了回收页面的复选框。如果是这样,此函数会导致再次显示上一页。问题在于这些字段包含用户刚刚输入的信息。现在,我想做的是在返回前一页之前清除上一页所有字段的状态。我尝试过做这样的事情,

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

但它似乎不允许我清除状态。我知道 SendMessageGetDlgItem 命令,但不知道有任何方法允许我使用它们来清除包含在的文本框、复选框和列表框InstallOptions INI 文件。

任何人都可以指出我正确的方向,谢谢。如果您想查看更多脚本,请告诉我。

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 the 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻拂→两袖风尘 2024-12-14 00:39:01

所以你应该在 ini 中有这样的控件:

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

然后你可以像这样获得字段的句柄:

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

那么你可以像这样使用带有 $0SendMessage 命令:

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

此示例应该适用于文本框,对于其他控件,请参见以下内容:
在 NSIS 安装路径的“包含”下,有文件 Winmessages.nsh 以及要使用的消息密钥。

在我的测试中,我找到了设置复选框的关键:

SendMessage $0 ${BM_SETCHECK} 0 "0"

对于列表框,我发现:(未经测试)

LB_RESETCONTENT
LB_SELECTSTRING

希望有所帮助。
PS:如果您有任何疑问或批评,请告诉我。

PPS:

或者,您可以将 nsDialogs 宏与 HWND 句柄一起使用,即用于复选框:

${NSD_Uncheck} $0

有关此宏的更多信息如下:
nsDialogs 自述文件 - 宏

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

南城追梦 2024-12-14 00:39:01

您可以使用 SendMessage 重置每个控件,但随后您必须处理不同类型的控件,最好只重置 .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

..或重置状态并保留其他所有内容:(

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

这将重置链接和按钮控件,以便如果需要,将其过滤出循环)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文