Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

VB6 - Activating Hyperlinks using InkEdit

$
0
0
I found code that activated Hyperlinks with VB6 and a RichTextBox. If was far more complex than I wanted because it used subclassing. So I converted it to use an InkEdit box without subclassing. The underlining of the hyperlinks worked quite nicely, but passing the link to the browser did not work with the InkEdit Control.

So I set out to simplify it and make the browser work. I was pleasantly surprised at how simple it turned out to be.
Code:

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
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 Sub cmdEnable_Click()
    Const EM_AUTOURLDETECT = &H45B
    SendMessage txtMessage.hWnd, EM_AUTOURLDETECT, 1, ByVal 0
    txtMessage.SetFocus
End Sub

Private Sub Form_Load()
    txtMessage.Text = "Sample text with link." & vbCrLf & vbCrLf _
        & "https://www.us-cert.gov/ncas/alerts/TA17-318A" & vbCrLf & vbCrLf _
        & "J.A.Coutts" & vbCrLf
End Sub
Private Sub Timer1_Timer()
    Timer1.Enabled = False
    Debug.Print txtMessage.SelText
    ShellExecute 0&, "open", txtMessage.SelText, 0, 0, 1
End Sub

Private Sub txtMessage_DblClick()
    Timer1.Enabled = True
End Sub

Requirements: One form with, one InkEdit Control(txtMessage), one Command button (cmdEnable), and one Timer (Timer1) set to 20 ms and disabled. The InkEdit box should be multiline, IEM_disabled, with vertical Scrollbars.

The above code comes complete with a sample hyperlink. Click the command button to underline the hyperlink with the default blue. Double Click the link to send it to your default browser. As with the Spell Check, it required a 20 ms delay to allow the hyperlink to be selected

J.A. Coutts
Attached Images
 

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>