Jump to content

_GUICtrlRichEdit_AutoDetectURL() and _GUICtrlRichEdit_Copy()


rudi
 Share

Recommended Posts

Hello,

 

I want to put a URL as "clickable-copy-paste" within some text to the clipboard, so that it can be used in WinWord, Outlook, ....

 

This code is formatting the text properly in a RichText Edit, but when taking the content to the clipboard, the "clickable" of the URL get's lost.

 

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Color.au3>

$TxtTop="Your download will be available for 14 days only:" & @CRLF & _
"http://download.company.com/Your-Personal-Data-Collection.zip"

$TxtChecksum= @CRLF & @CRLF & "File Name: Your-Personal-Data-Collection.zip" & @CRLF & _
"File Size: 93440288 Bytes (89 MiB)" & @CRLF & _
"SHA256: 8B1D4F670501A7FEEC2CABE2E731EF7B34042570EE2A2579E91DO9AD7EBE7419"


PutToClipWithFormatting($TxtTop,$TxtChecksum)



Func PutToClipWithFormatting($TextDefault, $TextCourierNew6)
    Local $hGui, $iMsg, $idBtnNext, $iStep = 0
    Local $GuiW=800
    Local $GuiH=300
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")",$GuiW,$guiH)
    $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, $GuiW - 20, $GuiH - 20, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUISetState(@SW_SHOW)
    _GUICtrlRichEdit_AppendText($g_hRichEdit,$TextDefault)
    MsgBox(0, '', "after adding some text including an URL")
    _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit,True) ; URL Autodetection
    MsgBox(0, '', "after calling AutoDetectURL")
    _GUICtrlRichEdit_SetSel($g_hRichEdit, -1, -1) ; set selection behind last CHAR in RTF_EDIT
    _GUICtrlRichEdit_SetFont($g_hRichEdit, 8, "Courier New") ; change font to 8pt, Courier New
    Dim $aRGB[3]=[230,230,230]
    Dim $ColRef=_ColorSetCOLORREF($aRGB)
    _GUICtrlRichEdit_SetCharColor($g_hRichEdit, $ColRef)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & $TextCourierNew6)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & "Web Site: http://www.company.com/")
    _GUICtrlRichEdit_SetSel($g_hRichEdit, 0, -1) ; select all the content of the RTF_EDIT
    _GUICtrlRichEdit_Copy($g_hRichEdit) ; put the selection to the clipboard
    MsgBox(0, '', "After taking all content of RT to ClipBoard.")
    GUIDelete($hGui)
EndFunc   ;==>Example

 

The "Gray-8pt-Courier New" formatting is taken correctly to the clipboard, but not the "clickable" of the URL.

 

What do I miss?

 

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Confused:

It doesn't work for me.

  1. Not when started from SciTE <F5> when editing the script
  2. not when compiled 32bit
  3. not when compiled 64bit

 

This is now a different Windows 10 Pro 64bit PC I'm sitting at.

Differences are, that on this machine there is a 32bit Office 2013 installed. That one at work is 64bit Windows as well, but a 64bit Office 2016.

URL-not-clickable_text-formatted-correctly.jpg

RT-Edit-looks-as-expected.jpg

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

@Nine

Could you please confirm or withdraw your information, that when pasting into WinWord the URLs are both clickable?

Today I've tried some other PCs, Win7, Win10, and offices from version 2003 to 2016, 32bit, 2016 64bit Office as well.

 

For me *NONE* of the machines a "Paste" ended up with a clickable URL (WinWord an Outlook)

 

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

I do not have WinWord nor Outlook. 
I have Apache Open Office, and it does not make a clickable url because  of the security settings.

 

Are the urls clickable when you type them in ?

Edited by Dan_555
deleted the attached picture

Some of my script sourcecode

Link to comment
Share on other sites

Link to comment
Share on other sites

I think @Dan_555 has touch the root of your problem.  There is multiple places where you can remove the right to display URL as they are a potential threat.  I suggest you explore that direction.

Link to comment
Share on other sites

Thanks for your reply,

I believe this is *NOT* a rights issue at all, but the way the RichText Functions work -- in my opinion,  don't work properly.

 

It's working as a charm using the UDF _ClipPutHTML.AU3 by @Ascend4nt in this thread: 

 

 

 

#include <_ClipPutHTML.au3>
; ===============================================================================================================================
; <TestClipPutHTML.au3>
;
;   Test of <_ClipPutHTML.au3>
;
; Author: Ascend4nt
; ===============================================================================================================================

Local $sHtmlPre
Local $sURL = "http://download.company.com/Your-Personal-Download.ZIP"
Local $sSHA = "SHA256 CheckSum = XXXX"
Local $HtmlSuff = @CRLF & "</body>" & @CRLF & "</html>"
Local $sHTMLStr
Local $sPlainTextStr


$sHtmlPre = '<html><head>' & @CRLF & _
        '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">' & @CRLF & _
        "</head>" & @CRLF & "<body>" & @CRLF


$sHTMLStr = $sHtmlPre & _
        "The following download will be available for 7 days ONLY: <br>" & @CRLF & _
        '<a href="' & $sURL & '">' & StringTrimLeft($sURL, StringInStr($sURL, "/", 0, -1)) & '</a><br>' & @CRLF & _
        '<font face="Courier New" size="-2" color="#bbbbbb">' & $sSHA & '</font><br>' & _
        $HtmlSuff



$sPlainTextStr = "The following download will be available for 7 days ONLY: " & @CRLF & _
        @TAB & $sURL & @CRLF & _
        @TAB & $sSHA & @CRLF

_ClipPutHTML($sHTMLStr, $sPlainTextStr)

 

The clipboard content has both in it "all-in-one":

  1. HTML formatted content with the clickable URLs as wanted
  2. alternative "Plain-TXT-only" content, used e.g. when the email formatting is set to "plain-text-only"

Just a small modification was required, as the compiler complained for "missing separator character before keyword":

Func _ClipBoard_SendHTML(Const ByRef $sHTMLData,Const ByRef $sPlainText)

Okay --> Func _ClipBoard_SendHTML(Const ByRef $sHTMLData , Const ByRef $sPlainText)

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...