NSIS在按下按钮时重置文本和液滴列表

NSIS在按下按钮时重置文本和液滴列表,nsis,Nsis,希望你们能再次帮助我。我已经创建了一个自定义页面,在该页面中有几个文本字段a和两个droplist。我也有一个清除按钮,如果按下它会清除屏幕上的所有字段 注意:我在示例中使用了TestNotify.nsu中的代码 我遇到的问题是,当按clear键时,值会写入ini文件,因此在重新加载程序时,最后使用的字段会填充(即使我按clear键,也必须按两次才能清除ini文件) 第二个问题是如何将雾滴列表重置为按reset时选择的默认值 因此,我现在正在处理的唯一部分是clearbtn,因此,我如何将液滴列

希望你们能再次帮助我。我已经创建了一个自定义页面,在该页面中有几个文本字段a和两个droplist。我也有一个清除按钮,如果按下它会清除屏幕上的所有字段

注意:我在示例中使用了TestNotify.nsu中的代码

我遇到的问题是,当按clear键时,值会写入ini文件,因此在重新加载程序时,最后使用的字段会填充(即使我按clear键,也必须按两次才能清除ini文件)

第二个问题是如何将雾滴列表重置为按reset时选择的默认值

因此,我现在正在处理的唯一部分是clearbtn,因此,我如何将液滴列表重置为特定值,并在只按一次clear时从ini中清除数据

###Add Auto Start option

SetCompressor lzma
XPStyle on


!define FolderImages "Included\Images"

!define ImageIcon "Icon.ico"
!define ImageHDR "HDR.bmp"

!define PRODUCT_NAME "Test"
!define PRODUCT_VERSION "1.0"

!define MUI_ICON ".\${FolderImages}\${ImageIcon}"
Icon ".\${FolderImages}\${ImageIcon}"

!include WinVer.nsh
!include LogicLib.nsh
!include x64.nsh
!include FileFunc.nsh
!include MUI.nsh
!include WinMessages.nsh
!include InstallOptions.nsh
!include Sections.nsh
!include nsDialogs.nsh

 !define MUI_HEADERIMAGE
 !define MUI_HEADERIMAGE_BITMAP ".\${FolderImages}\${ImageHDR}"

Page custom SetCustom ValidateCustom

!insertmacro MUI_LANGUAGE "English"

Function SetCustom

  !insertmacro MUI_HEADER_TEXT  "Licence Key Generator" "Create or Read Licence Keys"


    #Hides the close button
    GetDlgItem $R0 $HWNDPARENT 1
    ShowWindow $R0 ${SW_HIDE}


  InstallOptions::initDialog ".\UserProfiles.ini"
  ; In this mode InstallOptions returns the window handle so we can use it
  Pop $0
  ; Now show the dialog and wait for it to finish
  InstallOptions::show
  ; Finally fetch the InstallOptions status value (we don't care what it is though)
  Pop $0
FunctionEnd

Function ValidateCustom

  # At this point the user has either pressed cancel or one of our custom buttons
  # We find out which by reading from the INI file
  ReadINIStr $0 ".\UserProfiles.ini" "Settings" "State"
  StrCmp $0 0 cancelbtn 
  StrCmp $0 19 createbtn 
  StrCmp $0 20 readbtn 
  StrCmp $0 21 comparebtn 
  StrCmp $0 22 clearbtn 
  Abort # Return to the page

createbtn:
Abort # Return to the page

readbtn:
Abort # Return to the page

comparebtn:
Abort # Return to the page

clearbtn:

  #Text Field 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 6" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  #Text Field 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 8" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  #Text Field 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 10" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  #Drop List ------------------------------------------------------------<<<< 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 12" "HWND"
  SendMessage $1 ${WM_SETTETX} 0 "STR:"

  #Text Field 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 14" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  #Drop List ------------------------------------------------------------<<<<
  ReadINIStr $1 ".\UserProfiles.ini" "Field 16" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  #Text Field 
  ReadINIStr $1 ".\UserProfiles.ini" "Field 18" "HWND"
  SendMessage $1 ${WM_SETTEXT} 0 "STR:"

  Abort # Return to the page

cancelbtn:

FunctionEnd

Section Dummy
SectionEnd
添加自动启动选项 SETZMA压缩机 XPStyle on !定义文件夹图像“包含\图像” !定义ImageIcon“Icon.ico” !定义ImageHDR“HDR.bmp” !定义产品名称“测试” !定义产品_版本“1.0” !定义MUI_图标“\${FolderImages}\${ImageIcon}” 图标“\${FolderImages}\${ImageIcon}” !包括WinVer.nsh !包括LogicLib.nsh !包括x64.nsh !包括FileFunc.nsh !包括梅兰芳 !包括WinMessages.nsh !包括InstallOptions.nsh !包括第3.nsh节 !包括nsDialogs.nsh !定义MUI_头图像 !定义MUI_HEADERIMAGE_位图“\${FolderImage}\${ImageHDR}” 页面自定义设置自定义验证自定义 !插入宏MUI_语言“英语” 函数集自定义 !insertmacro MUI_标题_文本“许可证密钥生成器”“创建或读取许可证密钥” #隐藏关闭按钮 GetDlgItem$R0$HWNDPARENT 1 ShowWindow$R0${SW_HIDE} InstallOptions::initDialog“\UserProfiles.ini” ; 在此模式下,InstallOptions返回窗口句柄,以便我们可以使用它 流行音乐$0 ; 现在显示对话框并等待它完成 InstallOptions::show ; 最后获取InstallOptions状态值(尽管我们不关心它是什么) 流行音乐$0 功能端 函数验证 #此时,用户已按下“取消”或我们的一个自定义按钮 #我们通过从INI文件中读取来找出哪个 ReadINIStr$0.“\UserProfiles.ini”“设置”“状态” StrCmp$0取消BTN StrCmp$0 19创建BTN StrCmp$0 20 readbtn StrCmp$0.21比较总吨 StrCmp$0 22净空BTN 中止#返回页面 createbtn: 中止#返回页面 readbtn: 中止#返回页面 比较TN: 中止#返回页面 clearbtn: #文本字段 ReadINIStr$1.“\UserProfiles.ini”字段6“HWND” SendMessage$1${WM_SETTEXT}0“STR: #文本字段 ReadINIStr$1.“\UserProfiles.ini”“字段8”“HWND” SendMessage$1${WM_SETTEXT}0“STR: #文本字段 ReadINIStr$1.“\UserProfiles.ini”字段10“HWND” SendMessage$1${WM_SETTEXT}0“STR:
#下拉列表------------------------------------------您可以通过发送以下消息来清除下拉列表:


您不应该使用相对的.INI路径,这只是自找麻烦,请使用完整路径

如果你发布一个最小的UserProfiles,这会有所帮助。iniWM_setttx是一个输入错误。我使用的是相对路径,因为这只是一个测试应用程序,在我运行后,我会调整它并将其移到我的真实应用程序中。我将在我的应用程序中使用$pluginsdir。退出安装程序时,$pluginsdir将被删除,因此不使用它将产生额外的错误,因为您可能不会每次都有一个新的.ini。
Var MyDir
Function .onInit
; Create example .ini
InitPluginsDir
StrCpy $MyDir $Temp ; Use something else in a real application, or use $PluginsDir.
WriteIniStr "$MyDir\UserProfiles.ini" "Settings" NumFields 4
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Type Button
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Left 0
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Right 50
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Top 0
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Bottom 14
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Text "&Clear"
WriteIniStr "$MyDir\UserProfiles.ini" "Field 1" Flags NOTIFY
WriteIniStr "$MyDir\UserProfiles.ini" "Field 2" Type Text
WriteIniStr "$MyDir\UserProfiles.ini" "Field 2" Left 0
WriteIniStr "$MyDir\UserProfiles.ini" "Field 2" Right 100
WriteIniStr "$MyDir\UserProfiles.ini" "Field 2" Top 15
WriteIniStr "$MyDir\UserProfiles.ini" "Field 2" Bottom 30
WriteIniStr "$MyDir\UserProfiles.ini" "Field 3" Type Droplist
WriteIniStr "$MyDir\UserProfiles.ini" "Field 3" Left 0
WriteIniStr "$MyDir\UserProfiles.ini" "Field 3" Right 100
WriteIniStr "$MyDir\UserProfiles.ini" "Field 3" Top 35
WriteIniStr "$MyDir\UserProfiles.ini" "Field 3" Bottom 99
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Type Button
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Left 55
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Right 105
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Top 0
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Bottom 14
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Text "&Add"
WriteIniStr "$MyDir\UserProfiles.ini" "Field 4" Flags NOTIFY
FunctionEnd

Function SetCustom
InstallOptions::initDialog "$MyDir\UserProfiles.ini"
; In this mode InstallOptions returns the window handle so we can use it
Pop $0
; Now show the dialog and wait for it to finish
InstallOptions::show
; Finally fetch the InstallOptions status value (we don't care what it is though)
Pop $0
FunctionEnd

Function ValidateCustom
# At this point the user has either pressed cancel or one of our custom buttons
# We find out which by reading from the INI file
ReadINIStr $0 "$MyDir\UserProfiles.ini" "Settings" "State"

StrCmp $0 1 clearbtn 
StrCmp $0 4 addbtn 
Abort # Return to the page


clearbtn:
    #Text Field 
    ReadINIStr $1 "$MyDir\UserProfiles.ini" "Field 2" "HWND"
    SendMessage $1 ${WM_SETTEXT} 0 "STR:"

    #Droplist Field
    ReadINIStr $2 "$MyDir\UserProfiles.ini" "Field 3" "HWND"
    SendMessage $2 ${CB_RESETCONTENT} 0 0
    DeleteIniStr "$MyDir\UserProfiles.ini" "Field 3" "ListItems"
    DeleteIniStr "$MyDir\UserProfiles.ini" "Field 3" "State"

    Abort # Return to the page

addbtn:
    ReadINIStr $1 "$MyDir\UserProfiles.ini" "Field 2" "State"
    ReadINIStr $2 "$MyDir\UserProfiles.ini" "Field 3" "HWND"
    SendMessage $2 ${CB_ADDSTRING} 0 "STR:$1"
    SendMessage $2 ${CB_SELECTSTRING} 0 "STR:$1"

    Abort # Return to the page

FunctionEnd