Jump to content
Sign in to follow this  
haputanlas

Completely Lost with RichEdit

Recommended Posts

Hey Guys,

I'm not sure how to approach this. Are there any tutorials?

I only essentially want to change the color of text and the functions don't seem to work.

It appears that I might have to select the text I want to change first, but I'm kind of embarrassed to say that I don't know how the hell to do that.

Share this post


Link to post
Share on other sites

Quick Example. Obviously I'm not doing something right. I would like "Hello" to be Red/Blue/Whatever and the "World" to be the standard black.

#include <GUIConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 448, 269, 192, 124)
$Edit1 = _GUICtrlRichEdit_Create($Form1,"", 16, 24, 417, 225)
GUISetState(@SW_SHOW)

_GUICtrlRichEdit_SetCharColor($Edit1,"00FF00")
_GUICtrlRichEdit_AppendText($Edit1,"Hello")

_GUICtrlRichEdit_SetCharColor($Edit1,"000000")
_GUICtrlRichEdit_AppendText($Edit1,"World")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit


    EndSwitch

WEnd
Edited by haputanlas

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 448, 269, 192, 124)
$Edit1 = _GUICtrlRichEdit_Create($Form1,"", 16, 24, 417, 225)
GUISetState(@SW_SHOW)

_GUICtrlRichEdit_AppendText($Edit1,"Hello ")
_GuiCtrlRichEdit_SetSel($Edit1, 0, 5)
_GUICtrlRichEdit_SetCharColor($Edit1,"0x00FF00")

_GUICtrlRichEdit_AppendText($Edit1,"Autoit ")
_GuiCtrlRichEdit_SetSel($Edit1, 6, 11)
_GUICtrlRichEdit_SetCharColor($Edit1,"0xFF0000")

_GUICtrlRichEdit_AppendText($Edit1,"World")
;~ _GuiCtrlRichEdit_SetSel($Edit1, 6, -1)
;~ _GUICtrlRichEdit_SetCharColor($Edit1,"0x000000")

_GuiCtrlRichEdit_Deselect($Edit1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit


    EndSwitch

WEnd

Share this post


Link to post
Share on other sites

Here it is in way of custom function

_GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)

#include <GUIConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 448, 269, 192, 124)
$Edit1 = _GUICtrlRichEdit_Create($Form1,"", 16, 24, 417, 225)
GUISetState(@SW_SHOW)

_GUICtrlRichEdit_AppendTextColor($Edit1, "Hello ", "0x00FF00")
_GUICtrlRichEdit_AppendTextColor($Edit1, "Autoit ", "0xFF0000")
_GUICtrlRichEdit_AppendTextColor($Edit1, "World", "0x000000")
;~ _GUICtrlRichEdit_AppendText($Edit1, "World")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($Edit1)            
            Exit
    EndSwitch
WEnd

Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)
    Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd)/2 ; RichEdit stores text as 2 Byte Unicode chars
    _GUICtrlRichEdit_AppendText($hWnd, $sText)
    _GUICtrlRichEdit_SetSel($hWnd, $iLength, $iLength + StringLen($sText)*2) ; position in 2 Byte "Unicode"
    _GUICtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GuiCtrlRichEdit_Deselect($hWnd)
EndFunc
Edited by Zedna

Share this post


Link to post
Share on other sites

Here it is in way of custom function

_GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)

#include <GUIConstants.au3>
#include <GuiRichEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 448, 269, 192, 124)
$Edit1 = _GUICtrlRichEdit_Create($Form1,"", 16, 24, 417, 225)
GUISetState(@SW_SHOW)

_GUICtrlRichEdit_AppendTextColor($Edit1, "Hello ", "0x00FF00")
_GUICtrlRichEdit_AppendTextColor($Edit1, "Autoit ", "0xFF0000")
_GUICtrlRichEdit_AppendTextColor($Edit1, "World", "0x000000")
;~ _GUICtrlRichEdit_AppendText($Edit1, "World")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($Edit1)            
            Exit
    EndSwitch
WEnd

Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)
    Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd)/2 ; RichEdit stores text as 2 Byte Unicode chars
    _GUICtrlRichEdit_AppendText($hWnd, $sText)
    _GUICtrlRichEdit_SetSel($hWnd, $iLength, $iLength + StringLen($sText)*2) ; position in 2 Byte "Unicode"
    _GUICtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GuiCtrlRichEdit_Deselect($hWnd)
EndFunc

This was it. Thanks, that function just helped make the entire UDF make sense.

Share this post


Link to post
Share on other sites

Also notice I added

_GUICtrlRichEdit_Destroy($Edit1)

It's very important because without it Autoit3.exe process was still running after closing GUI

and later after more tries it blocked CPU.

Yeah, I figured that one out pretty quickly after I tried the code.

Thanks though!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...