【问题标题】:Checkbox in NSISNSIS 中的复选框
【发布时间】:2017-04-07 06:13:36
【问题描述】:

我希望在 NSIS 中使用 MUI_PAGE_CUSTOMFUNCTION_SHOW 向默认目录页面添加一个基本复选框。但是,该复选框似乎没有以任何方式出现或运行。这是我尝试过的不同功能;我不确定是否需要抓取当前窗口才能绘制到它?任何建议将不胜感激。

!define MUI_PAGE_CUSTOMFUNCTION_SHOW "DirectoryShow"
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave"
!insertmacro MUI_PAGE_DIRECTORY

Var Checkbox

Function DirectoryShow
  ${NSD_CreateCheckbox} 0 0 50% 6% "CheckboxTest"
  Pop $Checkbox
  ${NSD_Check} $Checkbox
FunctionEnd

Function DirectoryLeave
  ${NSD_GetState} $Checkbox $0
  ${If} $0 <> 0
    MessageBox mb_ok "Checkbox checked."
  ${EndIf}
FunctionEnd

【问题讨论】:

  • 我认为你的复选框有错误的 x,y 或非法大小。看看我的定义 - ${NSD_CreateCheckbox} 50 193 350 8u $(DLG_InternetConnectionShortcut)
  • 没有这样的运气,即使尝试不同的坐标。有什么办法可以让详细打印出来看看问题可能是什么?

标签: checkbox nsis


【解决方案1】:

NSD_Create* 仅在 nsDialog 页面(Welcome 和 Finish MUI 页面)上受支持,但在像 Directory 这样的内部 NSIS 页面上不支持。

要在内部页面上创建控件,您必须手动调用CreateWindowEx Windows API 函数。其他一些 NSD 辅助宏仍然可以用于这些控件:

!include MUI2.nsh
!include nsDialogs.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW "DirectoryShow"
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English

Var Checkbox
Var CheckState ; Stored globally so we remember the choice if the user presses the back button and goes back to our page
!define CheckHeight 28

!ifmacrondef _Z= 
!error "NSIS 2.51 or 3.0rc1 or later required!"
!endif
!macro CreateNativeControl hParent cls style exstyle x y w h text ; Note: Only supports pixel coordinates
System::Call 'USER32::CreateWindowEx(i ${exstyle}, t "${cls}", ts, i ${style}, i ${x}, i ${y}, i ${w}, i ${h}, p ${hParent}, i0, i0, i0)p.s' "${text}"
!macroend

Function DirectoryShow
  ; Create some extra space by reducing the height of the top text:
  System::Call *(i,i,i,i)p.r0 ; NSIS 2.51+
  System::Call 'USER32::GetWindowRect(p$mui.DirectoryPage.Text, pr0)'
  System::Call 'USER32::MapWindowPoints(i0,p$mui.DirectoryPage,p$0,i2)'
  System::Call '*$0(i.r2,i.r3,i.r4,i.r5)'
  System::Free $0
  IntOp $5 $5 - ${CheckHeight}
  System::Call 'USER32::SetWindowPos(i$mui.DirectoryPage.Text,i,i,i,i$4,i$5,i0x6)'

  ; Create and initialize the checkbox
  IntOp $5 $3 + $5 ; y = TextTop + TextHeight
  !insertmacro CreateNativeControl $mui.DirectoryPage ${__NSD_CheckBox_CLASS} "${__NSD_CheckBox_STYLE}" "${__NSD_CheckBox_EXSTYLE}" 0 $5 300 ${CheckHeight} "CheckboxTest"
  Pop $Checkbox
  SendMessage $mui.DirectoryPage ${WM_GETFONT} 0 0 $0 ; Get the dialog font
  SendMessage $Checkbox ${WM_SETFONT} $0 1 ; and apply it to the new control
  System::Call 'USER32::SetWindowPos(i$Checkbox,i0,i,i,i,i,i0x33)' ; Make sure it is on top of the tab order
  ${IfThen} $CheckState == "" ${|} StrCpy $CheckState 1 ${|} ; Set the default if this is our first time
  ${NSD_SetState} $Checkbox $CheckState
FunctionEnd

Function DirectoryLeave
  ${NSD_GetState} $Checkbox $CheckState
  ${If} $CheckState <> 0
    MessageBox mb_ok "Checkbox checked."
  ${EndIf}
FunctionEnd

或者,您可以使用 Resource Hacker 修改实际页面 (...\NSIS\Contrib\UIs\modern.exe) 并使用 MUI_UI 应用新的 UI 文件,而不是在运行时创建控件。 (ChangeUI)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    相关资源
    最近更新 更多