Page 1 of 1
Making a part of StringGadget a hyperlink
Posted: Sat Apr 17, 2004 12:39 pm
by merendo
Hi all
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
Re: Making a part of StringGadget a hyperlink
Posted: Sun Apr 18, 2004 8:50 am
by PB
Why not just use multiple HyperLinkGadgets? Or do you need people to
be able to click links on some text they are entering? What's your aim?
Posted: Sun Apr 18, 2004 10:23 am
by merendo
The text is very liable to change... So multiple hyperlinks would not be a good solution, because i would have to re-create them everytime the text changes...
Posted: Sun Apr 18, 2004 10:37 am
by freak
You can put hyperlinks in an EditorGadget.
(and make it readonly, so it is kind of a textgadget)
I have ever tried that though.
Timo
Posted: Sun Apr 18, 2004 1:39 pm
by merendo
Well, and how do i put hyperlinks in an editorgadgets?
Posted: Sun Apr 18, 2004 3:04 pm
by El_Choni
Posted: Sun Apr 18, 2004 4:22 pm
by merendo
Hmm.... Well, that's a good example but it doesn't actually help me, because the text i want to be a hyperlink is not an URL, it's just normal text without www or .net;.com or whatever.
Posted: Sun Apr 18, 2004 9:48 pm
by RJP Computing
You could then use a webgadget. Just do the appropriate html and you should get the desired effect.
Posted: Tue Apr 20, 2004 1:33 pm
by merendo
Sorry, but i don't actually get what you mean...
Posted: Tue Apr 20, 2004 2:09 pm
by Dare2
Hi merendo.
Maybe trap mouseclicks, see if they were made in the region of your text, and act accordingly.
BTW, is your link for internal control (they click and your program then does something) or is it a link to a webpage?
Posted: Tue Apr 20, 2004 2:39 pm
by RJP Computing
I was just meaning you could write html to include the links as you desire. Then include that file and load it at your programs start. Then it will load the link page in the WebGadget too.
Just a thought. It might not work for your needs.
Posted: Tue Apr 20, 2004 2:42 pm
by freak
Here it is:
(i used EL_Choni's code as inspiration, thanks for that.)
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
Timo
Posted: Tue Apr 20, 2004 5:54 pm
by merendo
I need the programme to do something when a link is clicked, no external programme will be called or somethin' like that.
Freak, thanks for your code, it works perfectly though it's a bit complicated but i will get it, for sure. Thanks again!!!!