问题
Suppose I have following nsDialog label:
By clicking Accept I agree to the Example's License Agreement and Privacy Policy. You may access features that requires use of personal information. For more information, please download Example's Content Policy.
I want to insert the links in this label like below:
By clicking Accept I agree to the Example's License Agreement and Privacy Policy. You may access features that requires use of personal information. For more information, please download Example's Content Policy.*
I am able to create links with NSD_CreateLink
but I dont know how to make it as above.
回答1:
Create several labels with ${NSD_CreateLabel} like this ( '|' is separator ):
Label1 | Label2 |Label3| Label4 | Label5...
By clicking Accept I agree to the Example's | License Agreement | and | Privacy Policy | You may access...
So your text will be composed from several separate labels placed one by one to create your text.
Then simply use Linker plug-in (http://nsis.sourceforge.net/Linker_plug-in - few days ago I updated it to support transparent texts) with those labels which should be links:
Linker::link /NOUNLOAD $Label2Hwnd "http://www.unsigned-softworks.sk/"
Linker::link /NOUNLOAD $Label4Hwnd "http://www.graphical-installer.com/"
回答2:
There is no perfect solution to this other than writing your own plugin that hosts IE or something like that.
A RichEdit textbox is supposed to support links like that but I never got it working 100%, you might try to play with the RTF data some more.
If your target is XP+ you can use the SysLink control. If you search the NSIS forum you will see that there are some issues with it and SetCtlColors but it seems to work fine in a nsDialogs page on Win7.
!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
来源:https://stackoverflow.com/questions/18228810/nsis-inserting-links-in-label