Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlinks in Rich Text boxes 7

Status
Not open for further replies.

afryer

Programmer
Mar 9, 2004
207
GB
Hi All,

I am using a rich text box in once of my applications and what I need to be able to do is to automatically detect when a hyperlink has been added, i.e if it starts http:// or file:// then it should go to blue underlined in the same way as Microsoft Word.

Does anyone know if there is an easy way to do this or will I have to employ some kind of Windows Hook or something to check after each key press. If that is the case and I detect the http:// then how to I ensure that the hyperlink is displayed correctly and can be clicked?

Any help would be appreciated.

Andrew
 
Ahhhh the "Syntax Highlighting" saga continues ;-)

A) Do a keyword search for:
Syntax Highlighting
or
Syntax Coloring

B) If you don't find what you are looking for, start a new thread... that subject needs at least 1 thread all of it's own ;-)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Technokrat,
For Q#1 try replacing spaces with "%20", it works on my system... Of these six examples, five of them work. I have no idea why the third one doesn't...

file:C:\Program%20Files\Serv-U\Serv-U.hlp
file:/C:\Program%20Files\Serv-U\File%20Name.txt

Doesn't Work-> file://C:\Program%20Files\Serv-U\Serv-U.hlp

file:///C:\Program%20Files\Serv-U\Serv-U.hlp
file:////C:\Program%20Files\Serv-U\Serv-U.hlp
file:///////////////////C:\Program%20Files\Serv-U\Serv-U.hlp

BYW: Thanks for the excellent code stongm!
 
Just for interest's sake, there's an API call that will canonicalize URLs (make them RFC compliant) for you:

e.g.
Code:
[blue]Option Explicit

' Flags for InternetCanonicalizeUrl API function
Private Const ICU_NO_ENCODE = &H20000000   '// Don't convert unsafe characters to escape sequence
Private Const ICU_DECODE = &H10000000      '// Convert escape sequences to characters
Private Const ICU_NO_META = &H8000000      '// Don't convert meta path sequences
Private Const ICU_ENCODE_SPACES_ONLY = &H4000000  '// Encode spaces only
Private Const ICU_BROWSER_MODE = &H2000000 '// Special encode/decode rules for browser

Private Declare Function InternetCanonicalizeUrl Lib "wininet" Alias "InternetCanonicalizeUrlA" (ByVal pszUrl As String, ByVal pszCanon As String, lCharCount As Long, ByVal lFlags As Long) As Long

Private Sub Command1_Click()
    MsgBox GetCanonicalUrl("C:\Program Files\Serv-U\File Name.txt")
End Sub

Private Function GetCanonicalUrl(ByVal strSrc As String) As String
    Dim strCanon As String
    Dim result As Long
    Dim lsize As Long

    lsize = 1024
    strCanon = Space(lsize)
    result = InternetCanonicalizeUrl(strSrc, strCanon, lsize, ICU_BROWSER_MODE)
    If result Then
        GetCanonicalUrl = Left(strCanon, lsize)
    End If
End Function[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top