Here is my code:
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.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
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?




Reply With Quote