Const EM_AUTOURLDETECT = (WM_USER + 91)
Сообщение EM_AUTOURLDETECT включает или выключает возможность автоматического определения URL в rich edit control. Если такая возможность включена, то rich edit control сканирует текст, пытаясь найти текст, похожий на URL. Элемент управления обнаруживает URL, если слова начинаются на: http:, file:, mailto:, ftp:, https:, gopher:, nntp:, prospero:, telnet:, news:, wais:. При обнаружении URL, найденный текст подчеркивается и выделяется другим цветом. При этом изменяетя курсор на указательный палец (как в браузерах на ссылке)
В успешном случае возвращается 0. В противном случае возвращается ненулевое значение
' Добавьте код в стандартный модуль Public Type CHARRANGE cpMin As Long cpMax As Long End Type Public Type NMHDR hwndFrom As Long wPad1 As Integer idfrom As Integer code As Integer wPad2 As Integer End Type Public Type ENLINK nm As NMHDR msg As Integer wPad1 As Integer wParam As Integer wPad2 As Integer lParam As Integer chrg As CHARRANGE End Type Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long) Public Const WM_USER = &H400 Public Const EM_AUTOURLDETECT = (WM_USER + 91) Public Const RICHEDIT_CLASSA = "RichEdit20A" Public Const WS_EX_CLIENTEDGE = &H200& Public Const WS_VISIBLE = &H10000000 Public Const ES_MULTILINE = &H4& Public Const WS_CHILD = &H40000000 Public Const EM_SETEVENTMASK = (WM_USER + 69) Public Const ENM_LINK = &H4000000 Public Const GWL_WNDPROC = (-4) Public Const WM_NOTIFY = &H4E Public Const EN_LINK = &H70B Public IDC_RICHEDIT As Long Public WinProcOld As Long Public hwndRichEdit As Long Public hModule As Long Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim tNMH As NMHDR Dim tEN As ENLINK Dim strText As String ' If a notification message is recieved ' then... If wMsg = WM_NOTIFY Then RtlMoveMemory tNMH, ByVal lParam, Len(tNMH) If (tNMH.hwndFrom = hwndRichEdit) And (tNMH.code = EN_LINK) Then RtlMoveMemory tEN, ByVal lParam, Len(tEN) End If End If WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&) End Function Sub SubClassWnd(hwnd As Long) WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc) End Sub Sub UnSubclassWnd(hwnd As Long) SetWindowLong hwnd, GWL_WNDPROC, WinProcOld& WinProcOld& = 0 End Sub ' Добавьте код в форму Private Sub Form_Load() 'Subclass the our main window so we can ' track when a link is hit SubClassWnd hwnd IDC_RICHEDIT = 4096 'Load the richedit 2 library hModule = LoadLibrary("Riched20.dll") If hModule Then 'Create the richedit window hwndRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASSA, "(Введите URL)", WS_CHILD Or WS_VISIBLE Or ES_MULTILINE, 32, 32, 200, 200, hwnd, IDC_RICHEDIT, App.hInstance, 0) 'Set it up, such that it can automatical ' ly detect URLs SendMessage hwndRichEdit, EM_SETEVENTMASK, 0, ByVal ENM_LINK Call SendMessage(hwndRichEdit, EM_AUTOURLDETECT, 1, ByVal 0) Else MsgBox "Cannot initialize RichEdit." Unload Me End If End Sub Private Sub Form_Terminate() 'Free the library from memory FreeLibrary hModule End Sub Private Sub Form_Unload(Cancel As Integer) 'Unsubclass the window UnSubclassWnd hwnd End Sub