NSD_Create*
僅支持nsDialog頁(歡迎和完成MUI頁),但並不像目錄中的內部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
或者,而不是建立在運行時的控制,你可以只修改實際的頁面(... \ NSIS \的Contrib \用戶界面\ modern.exe)與Resource Hacker並應用新的UI文件與MUI_UI
(ChangeUI
)
我認爲您的複選框有錯誤的x,y或非法大小。看看我的定義 - \t $ {NSD_CreateCheckbox} 50 193 350 8u $(DLG_InternetConnectionShortcut) –
沒有這樣的運氣,即使嘗試不同的座標。有沒有什麼辦法讓詳細打印可能看到問題可能是什麼? – MateoConLechuga