我的要求是
我想向“许可协议”自定义屏幕添加一个新按钮(“打印”)。为此,我编写了以下代码。它正在编译,但未显示“打印”按钮。
请帮助我解决此问题。还有在安装程序屏幕上创建新按钮的最简单方法吗?
; Pages
!insertmacro MUI_PAGE_WELCOME
;Customizing the License Page Text
!define MUI_TEXT_LICENSE_TITLE "End-User License Agreement"
!define MUI_TEXT_LICENSE_SUBTITLE "Please read the following license agreement carefully"
!define MUI_INNERTEXT_LICENSE_BOTTOM ""
!define MUI_INNERTEXT_LICENSE_TOP ""
!define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ""
!define MUI_PAGE_CUSTOMFUNCTION_LICENSESHOW MyLicenseShowCallback
Function MyLicenseShowCallback
; You are supposed to use ChangeUI (or MUI_UI) and a modified ui file to add new buttons but this example adds the button at run-time...
GetDlgItem $0 $hwndparent 2 ; Find cancel button
System::Call *(i,i,i,i)i.r1
System::Call 'USER32::GetWindowRect(ir0,ir1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(i$hwndparent,ir1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $2 + $4 ;x
IntOp $2 $2 + 8 ;x+padding
System::Call 'USER32::CreateWindowEx(i 0,t "Button",t "Print",i ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},i r2,i r3,i r4,i r5,i $hwndparent,i 0x666,i 0,i 0)i.r0'
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
SendMessage $mui.LicensePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_LICENSE_TITLE)"
FunctionEnd
Function onmybtnclick
MessageBox mb_ok "You clicked me!"
FunctionEnd
答案 0 :(得分:0)
为此,我编写了以下代码
您确定吗?看起来很像{strong>我在a answer here中写的代码。
您未能正确阅读MUI文档,也未能正确调整发现的示例代码。
MyLicenseShowCallback
永远不会执行,因为您使用了错误的定义,正确的名称是MUI_PAGE_CUSTOMFUNCTION_SHOW
。
另一个问题是,原始代码将新按钮放置在经典NSIS UI中的“取消”按钮旁边,但是“取消”按钮在MUI中位于其他位置,并且按钮最终不在屏幕上显示。
此代码只是将按钮放置在用户界面的左侧
Var PrintBtn
!include MUI2.nsh
!include LogicLib.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HidePrintButton
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE HidePrintButton
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function HidePrintButton
${IfThen} $PrintBtn P<> 0 ${|} SendMessage $PrintBtn ${WM_CLOSE} 0 0 ${|}
FunctionEnd
Function MyLicenseShowCallback
GetDlgItem $0 $hwndparent 2 ; Find cancel button so we can copy its size and y position.
System::Call *(i,i,i,i)p.r1
System::Call 'USER32::GetWindowRect(pr0,pr1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(p$hwndparent,pr1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $4 / 5 ; Calculate x padding based on the width but you can put any value you want in $2
System::Call 'USER32::CreateWindowEx(i 0,t "Button",t "Print",i ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},i r2,i r3,i r4,i r5,p $hwndparent,p 0x666,p 0,p 0)p.r0'
StrCpy $PrintBtn $0
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd
Function onmybtnclick
MessageBox mb_ok "You clicked me!"
FunctionEnd