Is it possible to make a part of the content of a StringGadget (with #PB_String_ReadOnly flag) a hyperlink? Or even more than one part?
For example:

If it is possible, how can it be done?
Thanks for any help! merendo



Code: Select all
; Some Stuff is not defined by PB
;
Structure CHARFORMAT2
cbSize.l
dwMask.l
dwEffects.l
yHeight.l
yOffset.l
crTextColor.l
bCharSet.b
bPitchAndFamily.b
szFaceName.b[#LF_FACESIZE]
_wPad2.w
wWeight.w
sSpacing.w
crBackColor.l
lcid.l
dwReserved.l
sStyle.w
wKerning.w
bUnderlineType.b
bAnimation.b
bRevAuthor.b
bReserved1.b
EndStructure
Structure ENLINK
nmhdr.NMHDR
msg.l
wParam.l
lParam.l
chrg.CHARRANGE
EndStructure
#EN_LINK = $70b
#ENM_LINK = $4000000
#CFM_LINK = $20
#CFE_LINK = $20
#Window = 0
#Editor = 0
Procedure Callback(Window, Message, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If Message = #WM_NOTIFY
*enlink.ENLINK = lParam
If *enlink\nmhdr\hwndfrom = GadgetID(#Editor) And *enlink\nmhdr\code = #EN_LINK
If *enlink\msg = #WM_LBUTTONDOWN
; ok, here we have detected a mousedown on a link.
; You have different ways to find out which one it was:
;
; Debug *enlink\chrg\cpMin ; <- this gives you the start char of the word
; Debug *enlink\chrg\cpMax ; <- this gives you the end of the word
;
; This gives you the text that was clicked:
;
Text$ = Space(*enlink\chrg\cpMax-*enlink\chrg\cpMin)
textrange.TEXTRANGE\lpstrText = @Text$
textrange\chrg\cpMin = *enlink\chrg\cpMin
textrange\chrg\cpMax = *enlink\chrg\cpMax
SendMessage_(GadgetID(#Editor), #EM_GETTEXTRANGE, 0, @textrange)
Debug Text$
; In this example, the Text$ method is not good, because two words
; are the same, so you have to select them by their position.
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(#Window, 0, 0, 400, 200, #PB_Window_Screencentered|#PB_Window_SystemMenu, "")
If CreateGadgetList(WindowID())
EditorGadget(#Editor, 50, 50, 300, 20)
; Some customisation on the RichEdit, to make it look
; like a textgadget:
; Set to readonly:
SendMessage_(GadgetID(#Editor), #EM_SETOPTIONS, #ECOOP_OR, #ECO_READONLY)
; Set background color:
SendMessage_(GadgetID(#Editor), #EM_SETBKGNDCOLOR, 0, GetSysColor_(#COLOR_BTNFACE))
; Enable the #EN_LINK event:
OldEventMask = SendMessage_(GadgetID(#Editor), #EM_GETEVENTMASK, 0, 0)
SendMessage_(GadgetID(#Editor), #EM_SETEVENTMASK, 0, #ENM_LINK|OldEventMask)
; now set the text for the gadget:
SetGadgetText(#Editor, "Click here to edit this part or this part")
; this enables the link when used with the #EM_SETCHARFORMAT message
format.CHARFORMAT2
format\cbSize = SizeOf(CHARFORMAT2)
format\dwMask = #CFM_LINK
format\dwEffects = #CFE_LINK
; Ok, now select each link word, and apply the format:
SendMessage_(GadgetID(#Editor), #EM_SETSEL, 6, 10)
SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
SendMessage_(GadgetID(#Editor), #EM_SETSEL, 19, 23)
SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
SendMessage_(GadgetID(#Editor), #EM_SETSEL, 32, 36)
SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
; reset the selection to nothing:
SendMessage_(GadgetID(#Editor), #EM_SETSEL, 0, 0)
; set the window callback to catch the message:
SetWindowCallback(@Callback())
; done.
;
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf
EndIf
End