Search code examples
windows-installernsis

is it possible to add a link to MUI_LICENSEPAGE_TEXT_BOTTOM?


I am attempting to add a hyperlink to the bottom text of the license page.

For example:

!define MUI_LICENSEPAGE_TEXT_BOTTOM "Click this link -> http://www.google.com/"

!insertmacro MUI_PAGE_LICENSE "${license}"

I have looked around, and I have found there is a linker plugin for doing this sort of thing: https://nsis.sourceforge.io/Linker_plug-in

This only seems to work for labels, though. Is it possible to do for the bottom text of the license page? I am also confused how the linker plugin works with FindWindow $0 "#32770" "" $HWNDPARENT how do we know the window number to use?


Solution

  • NSIS does not have great support for links on non-custom pages.

    You can use the Linker plug-in you found:

    !include MUI2.nsh
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW OnLicShow
    !define MUI_LICENSEPAGE_TEXT_BOTTOM "Click this link -> http://www.google.com/"
    !insertmacro MUI_PAGE_LICENSE "${__FILE__}"
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English
    
    Function OnLicShow
    !if ${MUI_SYSVERSION} >= 2
    StrCpy $0 $mui.LicensePage.Text
    !else
    FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $0 $0 1006 ; <-- Use MakeNsisW.exe=>Tools=>Window Info to find this id
    !endif
    Linker::link /NOUNLOAD $0 "http://www.google.com/"
    FunctionEnd
    

    Or this crazy thing:

    Unicode True
    RequestExecutionLevel User
    XPStyle On ; SysLink
    PESubsysVer 5.1 ; SysLink is XP+
    !include MUI2.nsh
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW OnLicShow
    !define MUI_LICENSEPAGE_TEXT_BOTTOM "Hello, click <A>this</A> if you dare"
    !insertmacro MUI_PAGE_LICENSE "${__FILE__}"
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English #*/
    
    Function OnLicShow
    !if ${MUI_SYSVERSION} >= 2
    StrCpy $0 $mui.LicensePage.Text
    !else
    FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $0 $0 1006 ; Use makensis.exe=>Tools=>Window Info to find this id
    !endif
    ${NSD_GetText} $0 $1
    ${NSD_SetText} $0 ""
    System::Call 'USER32::GetClientRect(pr0,@r2)'
    System::Call '*$2(i,i,i.r3,i.r4)'
    WndEvent::CreateWindow SysLink $1 ${WS_CHILD}|${WS_VISIBLE} 0 0 0 $3 $4 $0
    Var /Global mysyslink
    Pop $mysyslink
    GetFunctionAddress $1 SysLinkHandler
    WndEvent::AddHandler "NOTIFY" "$0" $1
    FunctionEnd
    !define /IfNDef NM_CLICK -2
    !define /IfNDef NM_RETURN -4
    Function SysLinkHandler
    ${If} $2 = ${NM_CLICK}
    ${OrIf} $2 = ${NM_RETURN}
        ${If} $mysyslink Z= $3
            ExecShell "" "http://example.com"
        ${EndIf}
    ${EndIf}
    FunctionEnd