Sign in to follow this  
Followers 0
bub

RichEdit with colored pieces of string

5 posts in this topic

I created this:

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


$GUI = GUICreate("colorful chalkboard",@DesktopWidth-300,@DesktopHeight-100,-1,-1, $DS_CONTEXTHELP+$DS_SETFOREGROUND+$WS_MINIMIZEBOX+$DS_MODALFRAME+$WS_SYSMENU+$WS_OVERLAPPED+$WS_BORDER+$WS_CLIPCHILDREN+$WS_DLGFRAME+$WS_CLIPSIBLINGS,$WS_EX_ACCEPTFILES+$WS_EX_WINDOWEDGE)
$hRichEdit = _GUICtrlRichEdit_Create($GUI, "", 0,0,@DesktopWidth-301,@DesktopHeight-120,BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
_GuiCtrlRichEdit_SetBkColor($hRichEdit,0xCCFFFF)
_GUICtrlRichEdit_SetZoom($hRichEdit,200)
_GuiCtrlRichEdit_SetCharColor($hRichEdit, 455)
$MENU = GUICtrlCreateMenu("hello")
$FILE = GUICtrlCreateMenuItem("&File",$MENU)
GUISetState()

_GUICtrlRichEdit_AppendText($hRichEdit,'<"window","center","center","500","500","img\main.png">' &@CRLF& _
'<"button","10","10","200","40","img\b1.png","img\b2.png","start","game.exe">'&@CRLF& _
'<"button","10","220","200","40","img\b3.png","img\b4.png","site","http:\\www.google.it">'&@CRLF& _
'<"progbar","220","10","160","90">'&@CRLF& _
'<"browser","10","100","480","390","http:\\www.google.it">'&@CRLF& _
'<"img","0","0","8","8","img\logo.png">' )
$TIMER = TimerInit()
Dim $SIMBOL[6] = [0x999999,0xCC9900,0xFFCC00,0x00000ff,0xff0000,0x009900]
Dim $ModEd,$Nume =0

while 1

_MovEdit($hRichEdit,$SIMBOL,$TIMER,$Nume)

    Switch GUIGetMsg()
        case -3
            Exit
        EndSwitch
    WEnd



func _MovEdit($EHnd,$SIMBOL,$TIMER,$Nur)
if TimerDiff($TIMER) > 200 then
$TEXT = _GUICtrlRichEdit_GetText($hRichEdit)
if $TEXT <> $ModEd then
$CHAR = StringSplit($TEXT,"")
For $CNum = 1 to $CHAR[0]
    if $CHAR[$CNum] = @CRLF or $CHAR[$CNum] = @Cr or $CHAR[$CNum] = @lf then $Nur = 0
if $CHAR[$CNum] = '"' then
    $SCNchr = $CNum
if $CHAR[0] <> $CNum and  $CHAR[$CNum+1] <> '"' Then
    For $CNum = $CNum+1 to $CHAR[0]
    if $CHAR[$CNum] = '"' then


                        _GUICtrlRichEdit_SetReadOnly($hRichEdit)
                        _GUICtrlRichEdit_HideSelection($hRichEdit)
            $CHARPOS = _GUICtrlRichEdit_GetSel($hRichEdit)
                _GuiCtrlRichEdit_SetSel($hRichEdit, $SCNchr, $CNum-1,True)
            _GuiCtrlRichEdit_SetCharColor($hRichEdit,$SIMBOL[$Nur])
                _GuiCtrlRichEdit_GotoCharPos($hRichEdit, $CHARPOS[0])
            _GUICtrlRichEdit_SetReadOnly($hRichEdit,False)
            _GUICtrlRichEdit_HideSelection($hRichEdit,False)

            $Nur = $Nur +1
            if $Nur = UBound($SIMBOL) then $Nur = 0
            ExitLoop

            EndIf
        next

EndIf
EndIf

Next
EndIf
$ModEd = $TEXT
$TIMER = TimerInit()
EndIf
EndFunc

Posted Image

The script works!!!

But it is unstable ...

if there are too many written, starts to malfunction very slowly.

can be solved?

Share this post


Link to post
Share on other sites



I created this:

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


$GUI = GUICreate("colorful chalkboard",@DesktopWidth-300,@DesktopHeight-100,-1,-1, $DS_CONTEXTHELP+$DS_SETFOREGROUND+$WS_MINIMIZEBOX+$DS_MODALFRAME+$WS_SYSMENU+$WS_OVERLAPPED+$WS_BORDER+$WS_CLIPCHILDREN+$WS_DLGFRAME+$WS_CLIPSIBLINGS,$WS_EX_ACCEPTFILES+$WS_EX_WINDOWEDGE)
$hRichEdit = _GUICtrlRichEdit_Create($GUI, "", 0,0,@DesktopWidth-301,@DesktopHeight-120,BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
_GuiCtrlRichEdit_SetBkColor($hRichEdit,0xCCFFFF)
_GUICtrlRichEdit_SetZoom($hRichEdit,200)
_GuiCtrlRichEdit_SetCharColor($hRichEdit, 455)
$MENU = GUICtrlCreateMenu("hello")
$FILE = GUICtrlCreateMenuItem("&File",$MENU)
GUISetState()

_GUICtrlRichEdit_AppendText($hRichEdit,'<"window","center","center","500","500","img\main.png">' &@CRLF& _
'<"button","10","10","200","40","img\b1.png","img\b2.png","start","game.exe">'&@CRLF& _
'<"button","10","220","200","40","img\b3.png","img\b4.png","site","http:\\www.google.it">'&@CRLF& _
'<"progbar","220","10","160","90">'&@CRLF& _
'<"browser","10","100","480","390","http:\\www.google.it">'&@CRLF& _
'<"img","0","0","8","8","img\logo.png">' )
$TIMER = TimerInit()
Dim $SIMBOL[6] = [0x999999,0xCC9900,0xFFCC00,0x00000ff,0xff0000,0x009900]
Dim $ModEd,$Nume =0

while 1

_MovEdit($hRichEdit,$SIMBOL,$TIMER,$Nume)

    Switch GUIGetMsg()
        case -3
            Exit
        EndSwitch
    WEnd



func _MovEdit($EHnd,$SIMBOL,$TIMER,$Nur)
if TimerDiff($TIMER) > 200 then
$TEXT = _GUICtrlRichEdit_GetText($hRichEdit)
if $TEXT <> $ModEd then
$CHAR = StringSplit($TEXT,"")
For $CNum = 1 to $CHAR[0]
    if $CHAR[$CNum] = @CRLF or $CHAR[$CNum] = @Cr or $CHAR[$CNum] = @lf then $Nur = 0
if $CHAR[$CNum] = '"' then
    $SCNchr = $CNum
if $CHAR[0] <> $CNum and  $CHAR[$CNum+1] <> '"' Then
    For $CNum = $CNum+1 to $CHAR[0]
    if $CHAR[$CNum] = '"' then


                        _GUICtrlRichEdit_SetReadOnly($hRichEdit)
                        _GUICtrlRichEdit_HideSelection($hRichEdit)
            $CHARPOS = _GUICtrlRichEdit_GetSel($hRichEdit)
                _GuiCtrlRichEdit_SetSel($hRichEdit, $SCNchr, $CNum-1,True)
            _GuiCtrlRichEdit_SetCharColor($hRichEdit,$SIMBOL[$Nur])
                _GuiCtrlRichEdit_GotoCharPos($hRichEdit, $CHARPOS[0])
            _GUICtrlRichEdit_SetReadOnly($hRichEdit,False)
            _GUICtrlRichEdit_HideSelection($hRichEdit,False)

            $Nur = $Nur +1
            if $Nur = UBound($SIMBOL) then $Nur = 0
            ExitLoop

            EndIf
        next

EndIf
EndIf

Next
EndIf
$ModEd = $TEXT
$TIMER = TimerInit()
EndIf
EndFunc

The script works!!!

But it is unstable ...

if there are too many written, starts to malfunction very slowly.

can be solved?

I don't know; I tried your script but it didn't go wrong, and you didn't explain what goes wrong.

You are using $CNum in a for loop and relying on the value of it being maintained outside of the loop. I think this can be unreliable, and in case this is this problem, try changing

For $CNum = $CNum+1 to $CHAR[0]
    if $CHAR[$CNum] = '"' then

to

$nn =  $CNum
  For $nn = $CNum+1 to $CHAR[0]
    $CNum = $nn
    if $CHAR[$CNum] = '"' then

Might be worth saving the text last converted text and seeing if the new text is the same as this to start with and then you wouldn't need to keep converting what has already been converted.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

the problem is the slowness of autoit :mellow:

cannot be solved :)

Share this post


Link to post
Share on other sites

the problem is the slowness of autoit :)

cannot be solved :)

That doesn't make any sense at all. You are using a GuiGetMsg() loop which imposes a time delay, then you execute the body of your function only if it has waited 200ms. After that, it doesn't have any obvious purpose.

What was it supposed to do? What did it do instead? What part of that implied slowness to you?

:mellow:

P.S. Why didn't you use _GUICtrlRichEdit_Destroy() so the script won't crash on exit?


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

Share this post


Link to post
Share on other sites

That doesn't make any sense at all. You are using a GuiGetMsg() loop which imposes a time delay, then you execute the body of your function only if it has waited 200ms. After that, it doesn't have any obvious purpose.

Yes.

I think some of the things I suggested could make a big difference. Most of the time is used up converting text which has already been converted.

Another thing worth trying is to only change the colour of the text which can be seen.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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