我尝试了ButtonEvent插件,但是当我运行编译示例时,它因内存访问错误而失败。也许它可以通过Windows API或其他东西使用System插件?任何人都可以展示如何做到这一点吗?
UPD:出现错误是因为我试图在Unicode NSIS上使用非unicode ButtonEvent。现在示例编译并执行OK,但是当我单击TryMe按钮时,不会调用回调函数并且没有任何反应。如何确定问题是什么?任何人都可以编译ButtonEventMUI.nsi并单击TryMe按钮吗?我下载了最新的ButtonEvent版本。使用NSIS 2.46 Unicode
答案 0 :(得分:3)
系统插件无法执行此操作,因为它无法将窗口子类化。
ButtonEvent插件适用于我(NSIS 2.46):
Name BtnTest
Outfile test.exe
Installdir "$temp"
RequestExecutionLevel user
BrandingText " " ;Button covers this text
!include nsDialogs.nsh ;For WS_*
Function .onGuiInit
; 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(i0,t "Button",t "Click Me",i${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},ir2,ir3,ir4,ir5,i $hwndparent,i 0x666,i0,i0)i.r0'
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
Page Directory
Page Instfiles
Section
SectionEnd