Decipher Posted June 7, 2012 Posted June 7, 2012 (edited) I would like to have a clickable text(hyperlink) in a RichEdit control besides a URL. To be more specific, I would like to display "Download" instead. How can I achieve this functionality? I have searched with no luck. Thanks for any help.Related Information:From GUIRichEdit.au3: Func _GUICtrlRichEdit_SetEventMask($hWnd, $iEventMask) If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iEventMask) Then Return SetError(102, 0, False) _SendMessage($hWnd, $EM_SETEVENTMASK, 0, $iEventMask) Return True EndFunc ;==>_GUICtrlRichEdit_SetEventMask$iEventMask = $ENM_LINK - Sends $EN_LINK notifications when the mouse pointer is over text having the link character. What is the link character "http://"? The following would work but is not a perfect solution "http://Download".From RichEditConstants.au3 used in _GUICtrlRichEdit_AutoDetectURL($hWnd, $fState)Global Const $__RICHEDITCONSTANT_WM_USER = 0x400 Global Const $EM_AUTOURLDETECT = $__RICHEDITCONSTANT_WM_USER + 91RichEdit Friendly Name Hyperlinks on MSDN$EN_LINK - http://msdn.microsoft.com/en-us/library/windows/desktop/bb787970%28v=vs.85%29.aspxGUIRegisterMsg($WM_COMMAND, "WM_NOTIFY") WM_NOTIFY is the function called when a link is clicked.Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $h_RichEdit Select Case $iCode = $EN_LINK Local $ENLINK = DllStructCreate($tagENLINK,$ilParam) Local $Link_Msg = DllStructGetData($ENLINK,4) If $Link_Msg = $WM_LBUTTONUP Then Local $Link = _GUICtrlRichEdit_GetTextRange($hWndFrom,DllStructGetData($ENLINK,7),DllStructGetData($ENLINK,8)) MsgBox(0, '', $Link) EndIf Case $iCode = $EN_MSGFILTER Local $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $ilParam) If DllStructGetData($tMsgFilter, 4) = $WM_RBUTTONUP Then ; WM_RBUTTONUP Local $hMenu = GUICtrlGetHandle($RichMENU[0]) _SetMenuTexts($hWndFrom, $RichMENU) _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd) EndIf EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYI am doing more research but from what I can tell this all done using DLLs therfore no easy solution that I will be able to conjure up.Suggested Methods:ITextRange2::SetURL methodITextRange2::GetURL methodI have no idea how to use these.Resolved see last post. Edited June 7, 2012 by Decipher Spoiler
Malkey Posted June 7, 2012 Posted June 7, 2012 Here is an example of hyperlinks in a RichEdit control that I played with last year to see what was possible. I hope it helps you. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("+!R", "_ToggleReadOnly") ;Shift+Alt+r - Toggle read only Opt('MustDeclareVars', 1) Global $hRichEdit Global $Header = "{\rtf1\ansi\deff0\readprot\annotprot{\fonttbl {\f0 Normal;}}" ; Courier or New Times New Roman or roman or Times New Roman Greek $Header &= "{\colortbl;\red0\green255\blue0;\red170\green0\blue0;\red255\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}" Main() Func Main() Local $hGui, $iMsg $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a \cf1 test\cf0 .\line ", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_LINK) _GUICtrlRichEdit_AutoDetectURL($hRichEdit, True) _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "\i\b http://www.autoitscript.com\i0\line ") _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "http://www.google.com\b0 \line ") _GUICtrlRichEdit_AppendText($hRichEdit, @CR & '{\field{\*\fldinst{HYPERLINK "C:\"}}{\fldrslt{\ul\cf5\b c:\\ [view directory]}}}\b0\f0\par ') _GUICtrlRichEdit_AppendText($hRichEdit, @CR & '{\field{\*\fldinst{HYPERLINK "Calc.exe"}}{\fldrslt{\ul\cf5\b Run Calculator}}}\b0\f0\par\par ') _GUICtrlRichEdit_AppendText($hRichEdit, @CR & "Click on a \highlight2\cf4\b hyperlink\b0\cf0\highlight0 .") _GUICtrlRichEdit_SetText($hRichEdit, $Header & "\fs24 " & _GUICtrlRichEdit_GetText($hRichEdit) & "\line ") ;\i\b - italics, bold; \cf4 - color front (font color) forth color in color table 1; \fs24 - font size 24 half points = 12 point characters. ; All need a trailing space. ;_GUICtrlRichEdit_SetZoom($hRichEdit, 250) GUISetState() While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndSelect WEnd EndFunc ;==>Main Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam) #forceref $hWnd, $iMsg, $iWparam Local $hWndFrom, $iCode, $tNMHDR, $tEnLink, $cpMin, $cpMax, $tMsgFilter, $sLink $tNMHDR = DllStructCreate($tagNMHDR, $iLparam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_LINK $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam) If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then $tEnLink = DllStructCreate($tagENLINK, $iLparam) $cpMin = DllStructGetData($tEnLink, "cpMin") $cpMax = DllStructGetData($tEnLink, "cpMax") $sLink = _GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax) ConsoleWrite($sLink & @LF) If StringInStr($sLink, "/") Then Run("C:\Program Files\Mozilla Firefox\firefox.exe " & $sLink) ;Run("Explorer.exe " & $sLink) ElseIf StringRight($sLink, 3) == "exe" Then ShellExecute($sLink) Else Run("Explorer.exe /e, " & $sLink) EndIf MsgBox(0, "", "Invoke your web browser here and point it to " & $sLink, 3) EndIf EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _ToggleReadOnly() Static $RO = 1 If $RO <> 1 Then ConsoleWrite("$RO = " & $RO & @LF) $RO = 1 _GUICtrlRichEdit_SetReadOnly($hRichEdit, True) Else ConsoleWrite("$RO = " & $RO & @LF) $RO = 0 _GUICtrlRichEdit_SetReadOnly($hRichEdit, False) EndIf EndFunc ;==>_ToggleReadOnly
Decipher Posted June 7, 2012 Author Posted June 7, 2012 (edited) That's exactly what I needed. ; Requires RTF Header Func _GUICtrlRichEdit_FriendlyHyperlink($sHyperLink, $sFriendlyName) Return '{field{*fldinst{HYPERLINK "' & $sHyperLink & '"}}{fldrslt{ulcf5b ' & $sFriendlyName & '}}}b0f0parpar ' EndFunc Usage: Global $sHeader = "{rtf1ansideff0readprotannotprot{fonttbl {f0 Normal;}}line " ; Carriage Return+Line Feed = 'line " Global $FriendlyLink = _GUICtrlRichEdit_FriendlyHyperlink('http://www.autoitscript.com/forum/topic/141238-richedit-friendly-name-hyperlinks/', 'RichEdit Friendly Name Hyperlinks?') _GUICtrlRichEdit_SetText($hWnd, $sHeader) _GUICtrlRichEdit_AppendText($hWnd, "line " & $FriendlyLink & "line ") Also @CRLF dosen't work when using this instead use "line " Thanks, Decipher Edited June 7, 2012 by Decipher Spoiler
Decipher Posted June 7, 2012 Author Posted June 7, 2012 Regarding the header syntax and other text formatting you need only look here: Rich Text Format (RTF) Specification, version 1.6Maybe this will save a lot of people a lot of time. Spoiler
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now