希望你们能再次帮助我。我创建了一个自定义页面,在该页面中是服务器文本字段和2个下拉列表。我还有一个清晰的按钮,如果按下它会清除屏幕上的所有字段。
注意:我在示例中使用了TestNotify.nsu中的代码
我遇到的问题是,当按下清除时,值被写入ini文件,因此在重新加载程序时,最后使用的字段填充(即使我按清除,我必须按两次清除ini文件)< / p>
其次是如何将下拉列表重置为按下重置时选择的默认值。
因此,我现在唯一的部分是clearbtn,所以如何将下拉列表重置为特定值,并在仅按一次清除时清除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
答案 0 :(得分:1)
您可以通过发送CB_RESETCONTENT
消息清除下拉列表:
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
你不应该使用相对.INI路径,这只是要求麻烦,使用完整路径!