没有可变字段的NSIS目录页面

问题描述 投票:0回答:1

在NSIS安装程序的目录页面中,我想显示安装路径,但不更改它。

enter image description here

我在Directory.nsh EnableWindow中创建字段:

    ;Get control handles
    FindWindow $mui.DirectoryPage "#32770" "" $HWNDPARENT
    GetDlgItem $mui.DirectoryPage.Text $mui.DirectoryPage 1006
    GetDlgItem $mui.DirectoryPage.DirectoryBox $mui.DirectoryPage 1020
    GetDlgItem $mui.DirectoryPage.Directory $mui.DirectoryPage 1019
    GetDlgItem $mui.DirectoryPage.BrowseButton $mui.DirectoryPage 1001
    GetDlgItem $mui.DirectoryPage.SpaceRequired $mui.DirectoryPage 1023
    GetDlgItem $mui.DirectoryPage.SpaceAvailable $mui.DirectoryPage 1024
    EnableWindow $mui.DirectoryPage.Directory 0
    EnableWindow $mui.DirectoryPage.BrowseButton 0

现在字段为灰色并被阻止:

enter image description here

但这不是我想要的:

  • 按钮应该消失

  • 目录字段应更大并且具有正常亮度,即正常字段

我该怎么办?

nsis
1个回答
0
投票

如评论中所述,这是一个坏主意。用户还可以在命令行上用$InstDir设置另一个/D

您可以将编辑字段设为只读,而不是禁用它,这样用户至少可以选择/复制文本。该控件可能仍显示为灰色,具体取决于活动的Windows视觉样式/主题。

您可以使用MUI_UI和自定义UI文件,或者在运行时调整控件的大小:

InstallDir "$Temp\Whatever"
!include WinMessages.nsh
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW LockDirPage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English

Function LockDirPage
EnableWindow $mui.DirectoryPage.BrowseButton 0
ShowWindow $mui.DirectoryPage.BrowseButton 0
SendMessage $mui.DirectoryPage.Directory ${EM_SETREADONLY} 1 ""
System::Call 'USER32::GetWindowRect(p$mui.DirectoryPage.Directory,@r1)'
System::Call 'USER32::GetWindowRect(p$mui.DirectoryPage.BrowseButton,@r2)'
System::Call *$2(i,i,i.r2)
System::Call *$1(i.r3,i.r4,i,i.r6)
IntOp $3 $2 - $3 ; Width
IntOp $4 $6 - $4 ; Height
System::Call 'USER32::SetWindowPos(p$mui.DirectoryPage.Directory,p0,i0,i0,ir3,ir4,i0x16)'
FunctionEnd
© www.soinside.com 2019 - 2024. All rights reserved.