Jump to content

Recommended Posts

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 + 91

RichEdit Friendly Name Hyperlinks on MSDN

$EN_LINK - http://msdn.microsoft.com/en-us/library/windows/desktop/bb787970%28v=vs.85%29.aspx

GUIRegisterMsg($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_NOTIFY

I 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 method

ITextRange2::GetURL method

I have no idea how to use these.

Resolved see last post.

Edited by Decipher
Spoiler

censored.jpg

 

Link to post
Share on other sites

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.

#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
Link to post
Share on other sites

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 by Decipher
Spoiler

censored.jpg

 

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mike1950r
      Hi,
      I have a problem with the scrollbar in edit control.
      In my case I use richedit, but it appears also in the "normal" editcontrol.
      The problem ONLY appears, when working with my program (including editcontrol) and another program like notpad on the other screen.
      It appears when using the scrollbar of notepad, then my scroll bar and so on ... (vertical scrollbars only)
      and then suddenly the area behind my scrollbar gets highlighted (black) like selected, above and below,
      if i move the mouse to the left during pressing, the whole area behind the scrollbar gets highlighted in black.
      When my program is loaded alone the problem NEVER happens.
      I have made two screenshots, 1st one when the problem appears, and the second one showing when moving to the left.
      I really have no idea and there is nothing special in my editcontrol.
      I would be really thankful, if someone could help me further to get this issue solved.
      thanks in advance
      cheers mike


       
    • By therks
      Hi there,
      So I've created this very simple "chat" program so that my brother and I can quickly and easily share text and links to other computers on the network. It just reads/writes to a text file that the script interprets/formats appropriately. I will put the script it in a shared network folder and then any of the computers can open and use it.
      For displaying the "chat" I'm currently using an embedded IE browser and formatting the text via HTML, but I've realized that this will cause problems with opening the links because it will use IE instead of the system's default browser (Chrome in our case). Any suggestions? (To be clear, I'm specifically looking for assistance on having text with clickable links that will open in the default browser.)
       
      For anyone interested, here's the code so far:
      #include <GUIConstants.au3> #include <GUIEdit.au3> #include <IE.au3> Opt('TrayIconDebug', 1) Global $CHAT_FILE = @ScriptDir & '\NetworkChat.txt' Main() Func Main() Local $hGUIMain = GUICreate('Network Chat', 500, 500, Default, Default, $WS_OVERLAPPEDWINDOW) Local $oEmbedIE = _IECreateEmbedded() Local $ob_EmbedIE = GUICtrlCreateObj($oEmbedIE, 5, 5, 490, 300) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) _IENavigate($oEmbedIE, 'about:blank') Local $dm_AccelTab = GUICtrlCreateDummy() Local $dm_AccelCtrlA = GUICtrlCreateDummy() Local $dm_AccelEnter = GUICtrlCreateDummy() Local $dm_AccelShiftEnter = GUICtrlCreateDummy() Local $dm_AccelPgUp = GUICtrlCreateDummy() Local $dm_AccelPgDn = GUICtrlCreateDummy() Local $ed_Chat = GUICtrlCreateEdit('', 5, 310, 470, 60, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT)) Local $aTabStop = [ 4 * 4 ] _GUICtrlEdit_SetTabStops($ed_Chat, $aTabStop) Local $bt_Send = GUICtrlCreateButton('>', 475, 310, 20, 60) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) GUICtrlSetState(-1, $GUI_DEFBUTTON) Local $ch_Timestamps = GUICtrlCreateCheckbox('Show &timestamps', 5, 370, 200, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT)) Local $ra_Enter = GUICtrlCreateRadio('&1. Enter to send / Shift+Enter for new line', 280, 370, 215, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) GUICtrlSetState(-1, $GUI_CHECKED) Local $ra_ShiftEnter = GUICtrlCreateRadio('&2. Shift+Enter to send / Enter for new line', 280, 390, 215, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) Local $aAccel = [ _ [ '{enter}', $dm_AccelEnter ], _ [ '+{enter}', $dm_AccelShiftEnter ], _ [ '{tab}', $dm_AccelTab ], _ [ '{pgup}', $dm_AccelPgUp ], _ [ '{pgdn}', $dm_AccelPgDn ], _ [ '^a', $dm_AccelCtrlA ] ] Local $aAccelSwap = $aAccel $aAccelSwap[0][0] = '+{enter}' $aAccelSwap[1][0] = '{enter}' GUISetAccelerators($aAccel) GUISetState() GUICtrlSetState($ed_Chat, $GUI_FOCUS) Local $sHTML, $aChatTime[2], $hFocused, $hIEControl = ControlGetHandle($hGUIMain, '', '[CLASS:Internet Explorer_Server; INSTANCE:1]') While 1 $hFocused = _WinAPI_GetFocus() $aChatTime[0] = FileGetTime($CHAT_FILE, 0, 1) If $aChatTime[0] <> $aChatTime[1] Then $sHTML = _LoadChat(BitAND(GUICtrlRead($ch_Timestamps), $GUI_CHECKED)) _IEDocWriteHTML($oEmbedIE, $sHTML) _IEAction($oEmbedIE, 'refresh') $oEmbedIE.document.parentwindow.scrollTo(0, $oEmbedIE.document.body.scrollHeight) $aChatTime[1] = $aChatTime[0] EndIf Local $iMsg = GUIGetMsg() If $iMsg > 0 Then ConsoleWrite($iMsg & @CRLF) Switch $iMsg Case $ch_Timestamps $aChatTime[1] = 0 Case $ra_Enter GUISetAccelerators($aAccel) Case $ra_ShiftEnter GUISetAccelerators($aAccelSwap) Case $dm_AccelPgUp $oEmbedIE.document.parentwindow.scrollBy(0, -200) Case $dm_AccelPgDn $oEmbedIE.document.parentwindow.scrollBy(0, 200) Case $dm_AccelCtrlA If $hFocused = GUICtrlGetHandle($ed_Chat) Then _GUICtrlEdit_SetSel($ed_Chat, 0, -1) Case $dm_AccelEnter If $hFocused = GUICtrlGetHandle($ed_Chat) Then If BitAND(GUICtrlRead($ra_Enter), $GUI_CHECKED) Then _SendChat($ed_Chat) Else _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF) EndIf EndIf Case $dm_AccelShiftEnter If $hFocused = GUICtrlGetHandle($ed_Chat) Then If BitAND(GUICtrlRead($ra_ShiftEnter), $GUI_CHECKED) Then _SendChat($ed_Chat) Else _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF) EndIf EndIf Case $bt_Send If $hFocused = GUICtrlGetHandle($ed_Chat) Then _SendChat($ed_Chat) Else GUICtrlSetState($ed_Chat, $GUI_FOCUS) EndIf Case $dm_AccelTab If $hFocused = GUICtrlGetHandle($ed_Chat) Then _GUICtrlEdit_ReplaceSel($ed_Chat, @TAB) Else GUICtrlSetState($ed_Chat, $GUI_FOCUS) EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc Func _EncodeForFile($sString) $sString = StringStripCR($sString) $sString = StringReplace($sString, '\', '\\') $sString = StringReplace($sString, @LF, '\n') $sString = StringReplace($sString, @TAB, '\t') Return $sString EndFunc Func _EncodeFromFile($sString) $sString = StringReplace($sString, '<', '<') $sString = StringReplace($sString, '>', '>') $sString = StringFormat($sString) $sString = StringReplace($sString, @TAB, '    ') $sString = StringReplace($sString, @LF, '<br />') $sString = StringRegExpReplace($sString, '(http://\S+)', '<a href="\1" target="_blank">\1</a>') Return $sString EndFunc Func _SendChat($iCtrl) Local $sChat = StringStripWS(GUICtrlRead($iCtrl), 3) If $sChat Then FileWrite($CHAT_FILE, @CRLF & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @TAB & @ComputerName & @TAB & _EncodeForFile($sChat)) GUICtrlSetData($iCtrl, '') Return True EndIf EndFunc Func _LoadChat($iShowTS) Local $aLines = FileReadToArray($CHAT_FILE), _ $sOutput = '<style>' $sOutput &= 'body, table { margin: 0; font-family: Arial; font-size: 0.8em; border-collapse: collapse; width: 100%; } ' $sOutput &= 'tr { vertical-align: top; text-align: left; } ' $sOutput &= '.name_column { white-space: nowrap; } ' $sOutput &= '.text_column { width: 100%; } ' $sOutput &= '.row1 { background: #eee; } ' $sOutput &= '.date { background: #bef; text-align: center; border: solid #000; border-width: 1px 0; } ' If Not $iShowTS Then $sOutput &= '.timestamp { display: none }' $sOutput &= '</style>' $sOutput &= '<table>' Local $sDateMem For $L = 0 To @extended-1 If Not $aLines[$L] Then ContinueLoop Local $aRegExLine = StringRegExp($aLines[$L], '(.+)\t(.+)\t(.+)', 1), $sChat If Not @error Then $aDateTime = _FormatTime($aRegExLine[0]) If $aDateTime[0] <> $sDateMem Then $sOutput &= '<tr><th class="date" colspan="2">' & $aDateTime[0] & '</th></tr>' $sDateMem = $aDateTime[0] EndIf $sOutput &= '<tr class="row' & Mod($L, 2) & '" title="' & $aDateTime[1] & '">' & _ '<th class="name_column"><span class="timestamp">[' & $aDateTime[1] & '] </span>' & $aRegExLine[1] & '</th>' & _ '<td class="text_column">' & _EncodeFromFile($aRegExLine[2]) & '</td></tr>' & @CRLF EndIf Next $sOutput &= '</table>' Return $sOutput EndFunc Func _FormatTime($sTime) Local $aMonths = StringSplit('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec', '|') Local $aReturn[2] Local $aRegEx = StringRegExp($sTime, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', 1) If Not @error Then $aReturn[0] = $aRegEx[0] &'-'& $aMonths[Int($aRegEx[1])] &'-'& $aRegEx[2] $aReturn[1] = $aRegEx[3] &':'& $aRegEx[4] &':'& $aRegEx[5] EndIf Return $aReturn EndFunc
       
    • By rudi
      Hello,
      very propably this has been asked before, well, I miss the thread(s) ...
      Is there a command line switch to tell the SciTE setup EXE to install silently ("/S") *AND* to end up with "edit" (instead of "run") as system wide default action for *.au3 files?
       

       
      As it can be done with the config tool:
      https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/SciTEConfigb1.PNG
       
      Regards, Rudi.
    • By nacerbaaziz
      Hi dears
      How are you?
      I have a question, to you please.
      How do I create an edit box for numbers only and does not accept letters? using autoit
      greetings to all
      I hope you help ME
      Thanks to all in advance
    • By Simpel
      Hi,
      I'm trying to create a console reader. All is working but I have a problem with the look. I want the line numbers with another backgroundcolor in silver. I made this with a small silver label. The edit control over the label has a transparent background.
      But if I start the prog then i can see how the line numbers wipe the silver background off. And if I click into the Edit then the silver label disappears completely.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <StaticConstants.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $g_iZaehler = 0 Global $g_hGUI = GUICreate("Console: StdoutRead" , 800, 800, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $text = GUICtrlCreateEdit("",10,30,780,760, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY + $ES_NOHIDESEL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $g_LaZeilen = GUICtrlCreateLabel("Zeilen: " & StringFormat("% 5d", $g_iZaehler), 680, 10, 100, 9, $SS_LEFTNOWORDWRAP) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) Global $g_hCbFreeze = GUICtrlCreateCheckbox("&Freeze", 13, 5, 90) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlCreateLabel("", 11, 31, 42, 758) ; soll die Ziffern andersfarbig hinterlegen GUICtrlSetBkColor(-1, $COLOR_SILVER) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW) Global $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) While 1 Sleep(200) $g_iZaehler += 1 $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) WEnd Func _Exit() Exit EndFunc Do you have any suggestions.
      Regards, Conrad
×
×
  • Create New...