Search code examples
nsis

Add checkbox AND radiobutton on license page


I'm writing scripts in Nsis and I need to have the option radio button on my license page AND a checkbox for another confirmation.
Is it possible to do so because if I try to insert both the higher priority is the checkbox and I'm missing radio buttons.
Preferable I would like to just modify the license page without creating a custom page!

Thanks for your help!


Solution

  • Option A:

    Use a modified (Resource Hacker) license page and apply it with ChangeUI (Or MUI_UI) and then use SendMessage to get the state at runtime.

    Option B:

    Create a new checkbox at runtime with the system plugin:

    !include nsdialogs.nsh
    !include MUI2.nsh
    !define MUI_LICENSEPAGE_RADIOBUTTONS
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow
    !define MUI_PAGE_CUSTOMFUNCTION_LEAVE licleave
    !insertmacro MUI_PAGE_LICENSE "${__FILE__}"
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE "English"
    
    Function licshow
    System::Call '*(i,i,i,i)i.r1'
    FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $2 $0 0x40A
    System::Call 'USER32::GetWindowRect(ir2,ir1)'
    System::Call 'USER32::MapWindowPoints(i0,ir0,ir1,i1)'
    System::Call '*$1(i.r6,i.r7)'
    System::Call 'USER32::GetClientRect(ir2,ir1)'
    System::Call '*$1(i,i,i.r8,i.r9)'
    IntOp $9 $9 + 3 ;padding
    IntOp $7 $7 - $9
    GetDlgItem $2 $0 0x3EE
    System::Call 'USER32::GetClientRect(ir2,ir1)'
    System::Call '*$1(i,i,i.r3,i.r4)'
    System::Free $1
    IntOp $4 $4 - $9 ;reduce size of label
    System::Call 'USER32::SetWindowPos(ir2,i,i,i,ir3,ir4,i6)'
    System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Some option",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i666,i0,i0)i.r2'
    SendMessage $0 ${WM_GETFONT} 0 0 $0
    SendMessage $2 ${WM_SETFONT} $0 1
    ${NSD_SetState} $2 1 ;check it
    FunctionEnd
    
    Function licleave
    FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $0 $0 666
    ${NSD_GetState} $0 $1
    MessageBox mb_ok "Checkbox=$1"
    FunctionEnd
    

    Screenshot