Making a part of StringGadget a hyperlink

Everything else that doesn't fall into one of the other PB categories.
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Making a part of StringGadget a hyperlink

Post 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: Image

If it is possible, how can it be done?

Thanks for any help! merendo
The truth is never confined to a single number - especially scientific truth!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Making a part of StringGadget a hyperlink

Post 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?
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post 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...
The truth is never confined to a single number - especially scientific truth!
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post by merendo »

Well, and how do i put hyperlinks in an editorgadgets?
The truth is never confined to a single number - especially scientific truth!
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

El_Choni
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post 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.
The truth is never confined to a single number - especially scientific truth!
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

You could then use a webgadget. Just do the appropriate html and you should get the desired effect.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post by merendo »

Sorry, but i don't actually get what you mean...
The truth is never confined to a single number - especially scientific truth!
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post 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.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post 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!!!!
The truth is never confined to a single number - especially scientific truth!
Post Reply