1

我尝试了 ButtonEvent 插件,但是当我运行已编译的示例时,它因内存访问错误而失败。也许它可以通过 Windows API 或其他方式与系统插件有关?谁能展示它是如何做到的?

UPD:出现错误是因为我尝试在 Unicode NSIS 上使用非 unicode ButtonEvent。现在示例编译并执行正常,但是当我单击 TryMe 按钮时,没有调用回调函数并且没有任何反应。如何确定是什么问题?任何人都可以编译 ButtonEventMUI.nsi 并单击 TryMe 按钮吗?我下载了最新的 ButtonEvent 版本。使用 NSIS 2.46 Unicode

4

1 回答 1

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

例子

于 2012-07-12T01:29:16.380 回答