Sign in to follow this  
Followers 0
Decipher

RichEdit Friendly Name Hyperlinks?

4 posts in this topic

#1 ·  Posted (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 + 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

 

Share this post


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Decipher

Spoiler

censored.jpg

 

Share this post


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
Sign in to follow this  
Followers 0

  • Similar Content

    • rudi
      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.
    • nacerbaaziz
      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
    • Simpel
      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
    • Messy_Code_Guy
      By Messy_Code_Guy
      All,
      I need some help with the following:
      1. Finding an image in a Word doc.  I have read the help file but I cannot figure out how to reference the image in the Word doc.
      2. Adding a hyperlink to that image.
      3. How would I loop the add hyperlink (text) and add hyperlink (image) to replace multiple links in a document.
      I have the add image and hyperlink working with the following code:
      $pic = "<PHOTO>" $picpath = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "Picture", 0) Local $oRange = _Word_DocFind($oDoc, $pic) _Word_DocPictureAdd($oDoc, $picpath, Default, Default, $oRange) _Word_DocFindReplace($oDoc, $pic, "", Default, 0, True, True) If @error Then $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9) _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a picture to the document. " & $picpath & " " & " @error = " & @error & " @extended = " & @extended) FileClose($file1) EndIf $Link = "<LINKEDIN>" $LinkedIn = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "LinkedIn", 0) Local $oRange = _Word_DocFind($oDoc, $Link) _Word_DocLinkAdd($oDoc, $oRange, $LinkedIn, Default, "Click here to visit my LinkedIn page. " & @CRLF & $LinkedIn, "LinkedIn") If @error Then $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9) _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a link to the document. " & $LinkedIn & " " & " @error = " & @error & " @extended = " & @extended) FileClose($file1) EndIf I just can't figure out how to find the images in a Word doc.
      Thanks for reading my post!
    • Chimp
      By Chimp
      Given an "Edit control" with Horizontal and Vertical scroll bars, setted with a monospace font,
      How can I know:
      1) the exact client area dimension (excluding the surface of the Vert and Horiz. scroll bars )
      2) the dimensions (in pixel or whatever) of the hidden portions of the "Edit control" that are on the right and/or on the left and/or over the top and/or below the bottom of the visible part?, that is:
      if the content of the Edit control is completly visible, then there are not hidden portions, while if the content of the control is biggher of the visible area, then there are hidden parts. How to know the dimensions of the not visible portions of the Edit control  on any given moment while I'm  scrolling vertically and/or horizzontaly or if I change the dimensions of the font as well?
      For example, when I set the Font dimension = 7, the whole text is visible, so the scrollbars are grayed out and parameters of the hidden parts should be all 0.
      Since I'm sure that my explanation in english is not clear, I post this short script to show in practice the question:
      Thanks for any suggestion.
      #include <GUIConstants.au3> HotKeySet("{ESC}", "End") Local $aData Local $Char = " 1 2 3 4 5 6 7 8" & @CRLF $Char &= "12345678901234567890123456789012345678901234567890123456789012345678901234567890" & @CRLF For $i = 3 To 22 $Char &= StringFormat('%02i', $i) & _StringReplicate(" ", 7) & "|" & _StringReplicate(" |", 7) & @CRLF Next Global $MyGui = GUICreate("", 600, 430) Global $hEdit1 = GUICtrlCreateEdit($Char, 0, 0, 500, 300, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_READONLY, $ES_MULTILINE)) GUICtrlSetFont(-1, 7, 0, 0, "Courier New") GUICtrlSetBkColor($hEdit1, 0xffffff) Local $idRadio1 = GUICtrlCreateRadio("Font size 7", 505, 10, 120, 20) Local $idRadio2 = GUICtrlCreateRadio("Font size 10", 505, 40, 120, 20) Local $idRadio3 = GUICtrlCreateRadio("Font size 12", 505, 70, 120, 20) Local $idRadio4 = GUICtrlCreateRadio("Font size 16", 505, 100, 120, 20) GUICtrlSetState($idRadio1, $GUI_CHECKED) GUICtrlCreateLabel("pixel hidden on the left : " & @CRLF & _ "pixel hidden on the right : " & @CRLF & _ "pixel hidden over the top : " & @CRLF & _ "pixel hidden below bottom : " & @CRLF & _ "Width of the edit : " & @CRLF & _ "Height of the edit : ", 5, 305, 400, 150) GUICtrlSetFont(-1, 12, 0, 0, "Courier New") Local $hParameters = GUICtrlCreateLabel("", 300, 305, 200, 150) GUICtrlSetFont(-1, 12, 0, 0, "Courier New") GUISetState() While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE End() Case $iMsg = $idRadio1 GUICtrlSetFont($hEdit1, 7, 0, 0, "Courier New") Case $iMsg = $idRadio2 GUICtrlSetFont($hEdit1, 10, 0, 0, "Courier New") Case $iMsg = $idRadio3 GUICtrlSetFont($hEdit1, 12, 0, 0, "Courier New") Case $iMsg = $idRadio4 GUICtrlSetFont($hEdit1, 16, 0, 0, "Courier New") EndSelect $aData = _CheckEdit($hEdit1) ; this should return actual parameters of the Edit <----- ??? how to get this data ??? GUICtrlSetData($hParameters, $aData[0] & @CRLF & $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aData[5]) WEnd Func _CheckEdit($hEdit1) ; <----- ??? how to get this data about the passed Edit ??? Local $aData[6] $aData[0] = "???" ; Hidden pixels on the left $aData[1] = "???" ; Hidden pixels on the right $aData[2] = "???" ; Hidden pixels over the top $aData[3] = "???" ; Hidden pixels below bottom $aData[4] = "???" ; Width of the visible portion of the Edit (without scrollbar surface) $aData[5] = "???" ; Height of the visible portion of the Edit (without scrollbar surface) Return $aData EndFunc ;==>_CheckEdit ; returns one or more chars replicated n times ; Example: ConsoleWrite(_StringReplicate('*', 5) & @CRLF) Func _StringReplicate($sChars = "", $iRepeats = 0) $sChars = String($sChars) $iRepeats = Int(Abs(Number($iRepeats))) Return StringReplace(StringFormat('%' & $iRepeats & 's', ""), " ", $sChars) EndFunc ;==>_StringReplicate Func End() If WinActive("[ACTIVE]") = $MyGui Then Exit EndIf EndFunc ;==>End