NSIS: How to add custom button to left bottom corner and handle it's click?

后端 未结 1 1496
野的像风
野的像风 2020-12-11 12:00

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 el

相关标签:
1条回答
  • 2020-12-11 12:30

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

    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
    

    Example

    0 讨论(0)
提交回复
热议问题