Jump to content

_GUICtrlRichEdit_SetAttributes()


Recommended Posts

Ok, i just started using this these rich edit controls because of my last post about editing a rich text doc. there is a lot variables that are undified, but i think you get the point.(i get them from Acitive Directory Query)

$obj_rtf = @AppDataDir & '\Microsoft\Signatures\' & $adObj_company & '_email_signature.rtf'

$frm_main = GUICreate('', 0, 0)
$ctrl_Edit = _GUICtrlRichEdit_Create($frm_main, '', 0, 0)

_GUICtrlRichEdit_StreamFromFile($ctrl_Edit, $obj_rtf)

_GUICtrlRichEdit_GotoCharPos($ctrl_Edit, 0)
_GUICtrlRichEdit_SetCharAttributes($ctrl_Edit, '+bo')

If $adObj_displayName > '' Then _GUICtrlRichEdit_InsertText($ctrl_Edit, $adObj_displayName & @LF)
If $adObj_title > '' Then _GUICtrlRichEdit_InsertText($ctrl_Edit, $adObj_title & @LF)
If $adObj_mail > '' Then _GUICtrlRichEdit_InsertText($ctrl_Edit, $adObj_mail & @LF)
If $adObj_mobile > '' Then _GUICtrlRichEdit_InsertText($ctrl_Edit, $adObj_mobile & " mobile" & @LF)
If $adObj_telephoneNumber > '' Then _GUICtrlRichEdit_InsertText($ctrl_Edit, $adObj_telephoneNumber & " direct" & @LF)

_GUICtrlRichEdit_StreamToFile($ctrl_Edit, $obj_rtf)

GUIDelete($frm_main)

Now, the $adObj_mail, i want to be a link, but I cant get the _GUICtrlRichEdit_SetAttribute($ctrl_Edit, '+li') to work. if i open the document and go to the end of that line, and hit "enter" it makes it a link, i have tried removing the @LF at the end of the line, and making it a new one, but that doesnt help, i m just trying to figure out if this is even possiable. thanks a lot.

Link to comment
Share on other sites

Since you didn't post a runnable demo, I can only guess at the issue, but it works by setting a selection, then setting the attribute on that selection:

#include <GuiConstants.au3>
#include <GuiRichEdit.au3>

$sRTF = @ScriptDir & "\Test1.rtf"
$sLink = "www.autoitscript.com"
$sText = "This is line one." & @CRLF & _
        "This is line two." & @CRLF & _
        "Line three is the link:  <insert link here>" & @CRLF & _
        "This is line four." & @CRLF & _
        "This is line five." & @CRLF
$hGUI = GUICreate('Test1.rtf', 400, 400)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, $sText, 10, 10, 380, 340)
$idButton = GUICtrlCreateButton("Create Link", 150, 360, 100, 30)
GuiSetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $idButton
            $aPos = _GUICtrlRichEdit_FindTextInRange($hRichEdit, "<insert link here>")
            _GUICtrlRichEdit_SetSel($hRichEdit, $aPos[0], $aPos[1])
            _GUICtrlRichEdit_ReplaceText($hRichEdit, $sLink)
            $aPos = _GUICtrlRichEdit_FindTextInRange($hRichEdit, $sLink)
            _GUICtrlRichEdit_SetSel($hRichEdit, $aPos[0], $aPos[1])
            _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "+li")
    EndSwitch
WEnd

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the help, it does work in your script, the problem is that im using this technique to actuall edit an exsiting .rtf file. so if you add the _GUICtrlRichEdit_StreamToFile($hRichEdit, $sRTF) [after you use the button to change to link] and push it to a file, it still doesn't retain the "+li" attribute, but if you use "+bo" for bold, that works. im starting to think this isn't possiable

#include <GuiConstants.au3>
#include <GuiRichEdit.au3>

$sRTF = @ScriptDir & "\test.rtf"
$sLink = "www.autoitscript.com"
$sText = "This is line one." & @CRLF & _
        "This is line two." & @CRLF & _
        "Line three is the link:  <insert link here>" & @CRLF & _
        "This is line four." & @CRLF & _
        "This is line five." & @CRLF
$hGUI = GUICreate('Test1.rtf', 400, 400)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, $sText, 10, 10, 380, 340)
$idButton = GUICtrlCreateButton("Create Link", 150, 360, 100, 30)
GuiSetState()

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_StreamToFile($hRichEdit, $sRTF)
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $idButton
            $aPos = _GUICtrlRichEdit_FindTextInRange($hRichEdit, "<insert link here>")
            _GUICtrlRichEdit_SetSel($hRichEdit, $aPos[0], $aPos[1])
            _GUICtrlRichEdit_ReplaceText($hRichEdit, $sLink)
            $aPos = _GUICtrlRichEdit_FindTextInRange($hRichEdit, $sLink)
            _GUICtrlRichEdit_SetSel($hRichEdit, $aPos[0], $aPos[1])
            _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "+li")
    EndSwitch
WEnd

but thanks again.

Edited by redLabel
Link to comment
Share on other sites

Hmm... this works, including the link in the saved file:

#include <GuiConstants.au3>
#include <GuiRichEdit.au3>

$sRTF = @ScriptDir & "\test.rtf"
$sLink = "www.autoitscript.com"
$sText = "This is line one." & @CRLF & _
        "This is line two." & @CRLF & _
        "Line three is the link:  <insert link here>" & @CRLF & _
        "This is line four." & @CRLF & _
        "This is line five." & @CRLF
$hGUI = GUICreate('Test1.rtf', 400, 400)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, $sText, 10, 10, 380, 340)
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
$idButton = GUICtrlCreateButton("Create Link", 150, 360, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            If Not _GUICtrlRichEdit_StreamToFile($hRichEdit, $sRTF) Then MsgBox(16, "Error", "Save failed: @error = " & @error)
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $idButton
            $aPos = _GUICtrlRichEdit_FindTextInRange($hRichEdit, "<insert link here>")
            _GUICtrlRichEdit_SetSel($hRichEdit, $aPos[0], $aPos[1])
            _GUICtrlRichEdit_ReplaceText($hRichEdit, $sLink)
    EndSwitch
WEnd

The _GuiCtrlRichEdit_AutoDetectURL() function creates a actual COM object link, not just color and underlining.

:x

P.S. Looks like you should also be able to create and/or copy a link in the Clipboard, then add it with _GUICtrlRichEdit_PasteSpecial(), but I don't have time to try it out.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I beg ask manfully to differ. How did you format the email? Just change this line in my previous script:

$sLink = "mailto:DontSpamMeBro@nospam.loc"

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

How is it an email link if you don't put "mailto:" in front of it? I thought that was the point all along.

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

if you create an RTF doc and open it in word, and type "ThisIsAnEmail@ADomain.com" then hit enter, it will make it a link. and you don't need the "Mailto:" infront of it. if i use the above sample, it will say "mailto:ThisIsAnEmail@ADomain.com". im try to do this without opening the document, and sending the 'keys' followed by an Send('{ENTER}') or something and with no 'mailto:'. but maybe that is what i will have to do.

Edited by redLabel
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...