NSIS运行时未创建按钮

时间:2017-11-21 10:27:22

标签: windows nsis

我尝试使用radiobuttons页面创建Windows安装程序,其中从找到的文件路径创建按钮。但只有第一个文件路径仅用于radiobutton创建。当我取消注释MessageBox行时,将显示所有文件路径。请问有人帮帮我吗?

谢谢

Function getButtons
  nsDialogs::Create 1018
  Pop $dialog
  ${NSD_CreateGroupBox} 0 0 100% 100% "These DLLs were found installed"
  # get available plugins
  ${locate::Open} "$dllDir" `/F=1 /D=0 /M=*.dll /B=1` $0
  StrCmp $0 0 0 loop
  MessageBox MB_OK "Error! No DLL files found..., $dllDir" IDOK close

  loop:
  # counter for y value
  StrCpy $R1 10
  # find possible plugins for installation
  ${Do}
    ${locate::Find} $0 $1 $2 $3 $4 $5 $6
    ${If} $1 == ""
      ${ExitDo}
    ${EndIf}
    ;MessageBox MB_OK "Path=$1" IDOK
    # calculate radiobutton y value
    IntOp $R1 $R1 + 20
    ${NSD_CreateRadioButton} 20 $R1 100% 50% "$1"
    Pop $hwnd
    nsDialogs::SetUserData $hwnd "$1"
    ${NSD_OnClick} $hwnd RadioClick
  ${Loop}
  close:
  ${locate::Close} $0
  ${locate::Unload}
  nsDialogs::Show
FunctionEnd

1 个答案:

答案 0 :(得分:0)

控件都在那里,它们只是不可见,因为你已将高度设置为50%并且无线电控件不透明。

你可以让它们透明:

${NSD_CreateRadioButton} 20 $R1 100% 50% "$1"
Pop $hwnd
SetCtlColors $hwnd SYSCLR:8 Transparent ; NSIS 3.1+
${NSD_AddExStyle} $hwnd ${WS_EX_TRANSPARENT} ; https://blogs.msdn.microsoft.com/oldnewthing/20121217-00/?p=5823

但是NSIS文档警告说:

  

警告:使用XPStyle on时,将复选框的背景颜色设置为透明可能无法正常工作。使用某些Windows主题时,背景可能是完全黑色而不是透明。

最好只是首先正确调整控件的大小:

!include nsDialogs.nsh

Page Custom getButtons
Page InstFiles

var hwnd

Function getButtons
nsDialogs::Create 1018
Pop $0

${NSD_CreateGroupBox} 0 0 100% 100% "These DLLs were found installed"
Pop $0

StrCpy $R1 0 ; Measured in dialog units, not pixels
FindFirst $0 $1 "$sysdir\sh*.dll"
loop:
    StrCmp $1 "" end
    IntOp $R1 $R1 + 12
    ${NSD_CreateRadioButton} 5u $R1u -20 12u "$1"
    Pop $hwnd
    nsDialogs::SetUserData $hwnd "$1"
    ${NSD_OnClick} $hwnd RadioClick
    FindNext $0 $1
    Goto loop
end:
FindClose $0

nsDialogs::Show
FunctionEnd

如果你不知道有多少文件,那么最好使用一个列表框,这样你就不会在对话框中耗尽空间。