NSIS:如何将自定义按钮添加到左下角并处理它的点击? [英] NSIS: How to add custom button to left bottom corner and handle it's click?

查看:49
本文介绍了NSIS:如何将自定义按钮添加到左下角并处理它的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried the ButtonEvent plugin, but when I run compiled example, it fails with memory access error. Maybe it is able to do with System plugin via Windows API or something else? Can anyone show how it can be done?

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

推荐答案

系统插件无法执行此操作,因为它无法对窗口进行子类化.

The system plugin cannot do this because it cannot subclass windows.

ButtonEvent 插件对我来说很好用(NSIS 2.46):

The ButtonEvent plugin works fine for me (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

这篇关于NSIS:如何将自定义按钮添加到左下角并处理它的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆