NSIS 运行时未创建按钮

NSIS runtime not created buttons

我尝试使用单选按钮页面创建 Windows 安装程序,其中按钮是在运行时从找到的文件路径创建的。但只有第一个文件路径仅用于创建单选按钮。当我取消注释 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` [=10=]
  StrCmp [=10=] 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} [=10=]      
    ${If}  == ""
      ${ExitDo}
    ${EndIf}
    ;MessageBox MB_OK "Path=" IDOK
    # calculate radiobutton y value
    IntOp $R1 $R1 + 20
    ${NSD_CreateRadioButton} 20 $R1 100% 50% ""
    Pop $hwnd
    nsDialogs::SetUserData $hwnd ""
    ${NSD_OnClick} $hwnd RadioClick
  ${Loop}
  close:
  ${locate::Close} [=10=]
  ${locate::Unload}
  nsDialogs::Show
FunctionEnd

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

你可以让它们透明:

${NSD_CreateRadioButton} 20 $R1 100% 50% ""
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 文档对此提出警告:

Warning: Setting the background color of check boxes to transparent may not function properly when using XPStyle on. The background may be completely black instead of transparent when using certain Windows themes.

最好一开始就正确调整控件的大小:

!include nsDialogs.nsh

Page Custom getButtons
Page InstFiles

var hwnd

Function getButtons
nsDialogs::Create 1018
Pop [=11=]

${NSD_CreateGroupBox} 0 0 100% 100% "These DLLs were found installed"
Pop [=11=]

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

nsDialogs::Show
FunctionEnd

如果您不知道有多少文件,那么最好使用列表框,这样您就不会 运行 超出对话框中的 space。