【问题标题】:NSIS: How to add custom button to left bottom corner and handle it's click?NSIS:如何在左下角添加自定义按钮并处理它的点击?
【发布时间】:2012-07-12 00:44:47
【问题描述】:

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

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

【问题讨论】:

  • 也许您可以添加更多详细信息:NSIS 版本(Unicode?)和插件版本/日期...
  • 2011 年有一个崩溃修复 (forums.winamp.com/showpost.php?p=2769430&postcount=11),因此请确保您的插件是最新的。
  • 我使用最新的 ButtonEvent Unicode 和 NSIS 2.46 Unicode。我更新了我的问题,谢谢提示。

标签: nsis


【解决方案1】:

系统插件不能这样做,因为它不能子类化窗口。

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

【讨论】:

  • 将 .onGuiInit 重命名为 myGuiInit 并在脚本顶部定义 MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
  • 嗯,当我单击您的按钮时,什么也没有发生。当我编译 ButtonEvent 示例时,什么也没有发生。我认为问题出在我的配置中。但我什至不知道从哪里开始搜索..
  • 尝试通过添加一些消息框来调试您的脚本 - 在 GetFunctionAddress $0 onmybtnclick 之前的 $0 上。
猜你喜欢
  • 2017-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多