Results 1 to 3 of 3

Thread: Detecting a URL in a RichTextBox (Resolved)

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Location
    Redondo Beach
    Posts
    25

    Detecting a URL in a RichTextBox (Resolved)

    Here is my code:

    Code:
    Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpoperation _ As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias _ 
    "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const SW_MINIMIZE = 6
    Private Const SW_MAXIMIZE = 3
    Private Const SW_RESTORE = 9
    Private Const SW_SHOWNORMAL = 1
    Private Const WM_USER = &H400
    Private Const EM_AUTOURLDETECT = (WM_USER + 91)
    
    Public Sub DetectURL(p_RichText As Object, p_blnDetect As Boolean)
        Dim lngRet As Long
        Dim strText As String
        
        With p_RichText
            ' this line is needed because the function will not update the
            ' url if you had it before
            strText = .Text
            ' send message to detect urls
            ' notice the Abs function. This is needed to pass 0 or 1
            ' in VB true is -1, so we have to get the absolute value of that
            lngRet = SendMessage(RichTextBox1.hWnd, EM_AUTOURLDETECT, Abs(p_blnDetect), ByVal 0)
            ' rewrite the text into the RichText so it will change all URLs if you
            'had them before
            .Text = strText
        End With
    End Sub
    
    Private Sub RichTextBox1_Change()
        DetectURL RichTextBox1, True
        RichTextBox1.SelStart = Len(RichTextBox1.Text)
    End Sub
    
    Private Sub RichTextBox1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        End Sub
    First the user can type text and somewhere in that text they can have a url. My code makes it look like it is a hyperlink.

    Now all that I need is to figure out how to find when the mouse is over this link and when the user selects it then execute that URL. How do I do this?
    Last edited by Jacque; Feb 12th, 2003 at 11:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width