NSIS:在标签中插入链接

时间:2013-08-14 10:07:15

标签: nsis

假设我有以下nsDialog标签:

  

单击“接受”即表示我同意示例的许可协议和隐私政策。您可以访问需要使用个人信息的功能。有关更多信息,请下载示例的内容政策。

我想在此标签中插入链接,如下所示:

  

点击“接受”即表示我同意示例的License AgreementPrivacy Policy。您可以访问需要使用个人信息的功能。有关详细信息,请下载示例Content Policy。*

我可以使用NSD_CreateLink创建链接,但我不知道如何按上述方式进行。

3 个答案:

答案 0 :(得分:3)

使用$ {NSD_CreateLabel}创建多个标签,如下所示('|'是分隔符):

              Label1             |    Label2     |Label3| Label4  |  Label5...

单击“接受”,我同意示例的|许可协议|和|隐私政策|你可以访问......

因此,您的文字将由逐个放置的几个单独标签组成,以创建您的文字。

然后只需使用链接器插件(http://nsis.sourceforge.net/Linker_plug-in - 几天前我更新它以支持透明文本),这些标签应该是链接:

Linker::link /NOUNLOAD $Label2Hwnd "http://www.unsigned-softworks.sk/"
Linker::link /NOUNLOAD $Label4Hwnd "http://www.graphical-installer.com/"

答案 1 :(得分:2)

除了编写自己的托管IE或类似内容的插件外,没有完美的解决方案。

一个RichEdit文本框应该支持这样的链接,但我从来没有让它100%工作,你可能会尝试更多地使用RTF数据。

如果你的目标是XP +,你可以使用SysLink控件。如果您搜索NSIS论坛,您将看到它和SetCtlColors存在一些问题,但它似乎在Win7上的nsDialogs页面中正常工作。

!include nsDialogs.nsh
!define /math EM_SETBKGNDCOLOR ${WM_USER} + 67
!define /math EM_GETTEXTRANGE ${WM_USER} + 75
!define /math EM_AUTOURLDETECT ${WM_USER} + 91
!define /math EM_SETTEXTEX ${WM_USER} + 97
!define EM_SETEVENTMASK 0x0445
!define ES_NOOLEDRAGDROP 8
!define ENM_LINK 0x4000000
!define EN_LINK 0x70B
!define NM_CLICK -2
!define NM_RETURN -4

XPStyle On ; Required by syslink (ComCtl v6)
Page Custom mypage mypageleave

var syslink

Function mypage
nsDialogs::Create 1018
pop $0

nsDialogs::CreateControl RichEdit20A ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${ES_READONLY}|${ES_NOOLEDRAGDROP} ${WS_EX_NOPARENTNOTIFY} 10u 10u 80% 10u ''
pop $0
System::Call user32::GetSysColor(i15)i.r1
SendMessage $0 ${EM_SETBKGNDCOLOR} 0 $1
SendMessage $0 ${EM_AUTOURLDETECT} 1 0
SendMessage $0 ${EM_SETEVENTMASK} 0 ${ENM_LINK}
System::Call *(i0,i0)i.r1
;//blogs.msdn.com/b/murrays/archive/2009/09/24/richedit-friendly-name-hyperlinks.aspx# but could not get it to fully work?
SendMessage $0 ${EM_SETTEXTEX} $1 'STR:{\rtf1{\field{\*\fldinst{HYPERLINK "http://example.org"}}{\fldresult{Richedit}}} says hello}'
System::Free $1
${NSD_OnNotify} $0 onrichclick

nsDialogs::CreateControl SysLink ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP} 0 10u 30u -20u 10u `Hello from <A>SysLink</A>...`
pop $syslink
${NSD_OnNotify} $syslink onsyslinkclick

nsDialogs::Show
FunctionEnd

Function mypageleave
System::Call 'user32::DestroyWindow(i $syslink)'
FunctionEnd

Function onrichclick
Pop $0
Pop $1
Pop $2
${If} $1 = ${EN_LINK}
    System::Call "*$2(i,i,i,i.r1,i,i,i.r2,i.r3)"
    ${If} $3 >= 0 ; Is it a CHARRANGE we can work with?
        ${If} $1 = ${WM_LBUTTONDOWN}
            IntOp $1 $3 - $2 ; length
            IntOp $1 $1 + 1 ; \0
            System::Call '*(ir2,ir3,i,i,&t$1)i.r1' ; TEXTRANGE + align + string
            IntOp $2 $1 + 16
            System::Call '*$1(i,i,ir2)'
            SendMessage $0 ${EM_GETTEXTRANGE} 0 $1
            System::Call "*$2(&t999.r2)"
            ExecShell open $2
            System::Free $1
        ${EndIf}
    ${EndIf}
${EndIf}
FunctionEnd

Function onsyslinkclick
Pop $0
Pop $1
Pop $2
${If} $0 = $syslink
    ${If} $1 = ${NM_CLICK}
    ${OrIf} $1 = ${NM_RETURN}
        System::Call `*$2(i,i,i,i,i.r3)`
        ${If} $3 == 0 ; link index
            ; This could probably be changed to extract the link from <A href="foo">...</A> in the syslink
            ExecShell open `http://example.com/`
        ${EndIf}
    ${EndIf}
${EndIf}
FunctionEnd

答案 2 :(得分:0)

我结束了:

使用这个 GetTextExtent:https://nsis.sourceforge.io/Get_text_dimensions 并调用:GetSystemMetrics(SM_CXMENUCHECK)

和一些小的垂直/水平像素修复。

!define FIRST_PART "I have read and accepted the "

...

; Get the dialog's default font in $R1

SendMessage $DIALOG ${WM_GETFONT} 0 0 $R1

; Get width for text into $R2
${GetTextExtent} $R1 "${FIRST_PART}" $R2 $R3

; Get checkbox width into $0

System::Call 'user32::GetSystemMetrics(i 71) i .r0' ;SM_CXMENUCHECK = 71

IntOp $1 $R2 + $0 ; width of checkbox + text into $1
IntOp $1 $1 - 2 ; -2 fixes some checkbox extra padding

; $1 contains the required width ($R3 the line height)

${NSD_CreateCheckbox} ${TEXT_LEFT_START_POS}u ${CHECKBOX_TOP}u $1u $R3u ${FIRST_PART}


; And now, the next label or link can be positioned by:

IntOp $1 ${TEXT_LEFT_START_POS} + $1 ; position after checkbox and text