2017-10-16 7 views
-1

J'espère que vous pourrez m'aider à nouveau. J'ai créé une page personnalisée, et dans cette page sont des champs de texte severa et 2 droplists. J'ai aussi un bouton d'effacement qui, s'il est pressé, efface tous les champs de l'écran.NSIS Réinitialisation du texte et des listes déroulantes à la pression d'un bouton

Note: J'ai utilisé le code de TestNotify.nsu dans les exemples

La question que j'ai est l'un, lorsque vous appuyez sur les valeurs claires sont écrites dans le fichier ini de sorte à rechargeant le programme les derniers champs utilisés Populate (Même si j'appuie sur effacer, je dois appuyer deux fois pour effacer le fichier ini)

Ensuite, comment réinitialiser la liste déroulante à la valeur par défaut que j'ai sélectionnée en appuyant sur reset. Donc la seule section sur laquelle je travaille est la clearbtn, alors comment puis-je réinitialiser les droplists à une valeur spécifique, et effacer les données de ini lorsque j'appuie sur clear une seule fois.

###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

Il serait utile si vous postez un UserProfiles.ini minimal – Anders

+0

WM_SETTETX est une faute de frappe. – Anders

Répondre

1

Vous pouvez effacer un droplist en envoyant le message 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 

Vous ne devriez pas utiliser des chemins relatifs .INI, qui est juste d'avoir des ennuis, utilisez les chemins complets!

+0

J'utilisais le chemin relatif puisque c'était juste une application de test après que je l'ai fait fonctionner je vais l'adapter et le déplacer vers ma vraie application. Je vais utiliser le $ pluginsdir dans mon application. –

+0

$ pluginsdir est supprimé lorsque vous quittez le programme d'installation, donc ne pas l'utiliser créera des bogues supplémentaires, car il se peut que vous n'ayez pas un nouveau fichier .ini à chaque fois. – Anders