使用复选框等在NSIS中创建新页面的问题

时间:2013-09-30 12:40:21

标签: checkbox installer nsis

我想在安装中插入一个新页面,其中包含两个名为Client versionServer version的复选框。在点击客户端版本时,目前没有任何特殊情况发生但是,如果选择了服务器版本,则应选择浏览选项来选择文件夹(这不是安装文件夹)。我发现这样做有些困难。我添加了两个复选框,一个文本框和浏览按钮。在复选框的onchange中我制作了浏览和文本框。

但现在的问题是 我希望一次只能检查一个复选框。

当服务器版本选中时,应显示浏览选项(现在可以使用),但如果再次取消选中,则该浏览选项应该消失(这不起作用,因为我无法为其编写代码)。

如果我点击此页面上的Next,然后使用Back返回同一页面,则我检查的所有控件或复选框都应该是原样。但是现在即使选择了服务器版本复选框,这些浏览选项也会消失(因为我还没有对此进行适当的编码)。

所以请帮我做所有这些事情。如果还有其他方法可以帮助我

!define PRODUCT_NAME "My application"   
!define PRODUCT_VERSION "1.0"

Var Dialog
Var Text
Var Text_State
Var Checkbox
Var Checkbox1
Var Checkbox_State
Var Checkbox1_State
var /GLOBAL SOURCETEXT
var /global SOURCE
var /global BROWSESOURCE

!include "MUI.nsh"
!include nsDialogs.nsh

!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

!insertmacro MUI_PAGE_WELCOME  
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Page custom InstallPageCreate checkinstdir
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show

Var InstallPageDialog
Var InstallPage.DirRequest
Var InstallPage.BrowseButton
Var mui.WelcomePage
Var mui.WelcomePage1
Var mui.WelcomePage.Image1
Var mui.WelcomePage.Title
Var mui.WelcomePage.Text
Var ImageHandle
Var mui.WelcomePage.Title.Font
Var LINK
Var LINK.Font
Var clickinstall
Var mui.WelcomePage.Image.Bitmap
var checked
var checked1
Var CheckBox.Font
var mui.WelcomePage1.Title1
var mui.WelcomePage.Title.Font1


Function InstallPageCreate
    nsDialogs::Create 1044
    Pop $mui.WelcomePage
    nsDialogs::SetRTL $(^RTL)
    SetCtlColors $mui.WelcomePage 0xffffff 0xffffff

    ${NSD_CreateLabel} 120u 70u 140u 14u "Choose the intallation method"
    Pop $clickinstall
    SetCtlColors $clickinstall "" "ffffff"  

    ${NSD_CreateCheckbox} 120u 90u 100% 10u "&Client version"
    Pop $CheckBox
    CreateFont $CheckBox.Font "$(^Font)" "08" "500"
    SetCtlColors $CheckBox "" "FFFFFF"
    SendMessage $CheckBox ${WM_SETFONT} $CheckBox.Font 0
    GetFunctionAddress $0 OnCheckbox1
    nsDialogs::OnClick $CheckBox $0

    ${NSD_CreateCheckbox} 120u 100u 100% 10u "&Server version"
    Pop $CheckBox1
    CreateFont $CheckBox.Font "$(^Font)" "08" "500"
    SetCtlColors $CheckBox1 "" "FFFFFF"
    SendMessage $CheckBox1 ${WM_SETFONT} $CheckBox.Font 0
    GetFunctionAddress $0 OnCheckbox2

    nsDialogs::OnClick $CheckBox1 $0

    ${If} $Checkbox_State == ${BST_CHECKED}
        ${NSD_Check} $Checkbox
    ${EndIf}

    ${If} $Checkbox1_State == ${BST_CHECKED}
        ${NSD_Check} $Checkbox1
    ${EndIf}

    nsDialogs::Show
    ${NSD_FreeImage} $mui.WelcomePage.Image.Bitmap
FunctionEnd


Function OnCheckbox2
    StrCpy $SOURCE "C:\"

    ${NSD_CreateText} 120u 120u 80u 12u "$SOURCE"
    pop $SOURCETEXT

    ${NSD_CreateBrowseButton} 280u 120u 35u 14u "Browse"
    Pop $InstallPage.BrowseButton

    ${NSD_OnClick} $InstallPage.BrowseButton Browsesource
FunctionEnd


Function OnCheckbox1
FunctionEnd


Function checkinstdir
    ${NSD_GetText} $Text $Text_State
    ${NSD_GetState} $Checkbox $Checkbox_State

    ${If} $Checkbox_State == ${BST_CHECKED}
        strcpy $checked 1
    ${else}
        strcpy $checked 0
    ${Endif}

    ${NSD_GetState} $Checkbox1 $Checkbox1_State

    ${If} $Checkbox1_State == ${BST_CHECKED}
        strcpy $checked1 1
    ${else}
        strcpy $checked1 0
    ${Endif}
FunctionEnd


Function Browsesource
    nsDialogs::SelectFolderDialog "Select Source Folder" "c:\"
    pop $SOURCE

    ${NSD_SetText} $SOURCETEXT $SOURCE
FunctionEnd


Section "MainSection" SEC01
SectionEnd


Section -Post
SectionEnd

0 个答案:

没有答案