Sign in to follow this  
Followers 0
Cheez

Rich Text

5 posts in this topic

Hi, I'm writing a basic chat client in AutoIt, and have decided to use a RichText object as the display for output of sent/received text (need to be able to manipulate text and field colours).

I'm using the example code provided in the AutoIt help file:

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

The foremost issue is with adding scrollbars (or any non-runtime property), for example:

$oRP.Multiline = True

Always crashes due to it being a non-runtime settable parameter.

The other issues tie together; adding and colouring text, and scrolling to that position. Currently the function looks something like:

Func Draw_Text($Text)
    Local $time, $in, $out
    $time = "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] "
    $in = $oRP.Text
    
    $out = $in

    ;There's a select colour switch in here.
    
    $out &= $time & $Text & @CRLF
    
    If $Log = 1 Then
        LogFile($time & $Text)
    EndIf
    
    $oRP.Text = $out
EndFunc

The problem with this lies with the fact that I require that individual lines to be different colours, is there a simple method to append a string with the desired colour (without affecting the colour of the previous entries?). The text also fails to scroll to the latest position (instead it scrolls to the top), not sure if this is related to the scrollbar issue (there is no vertical scrollbar).

Thanks for any assistance with this.

Share this post


Link to post
Share on other sites



Curiously the UDF pack I found (http://www.autoitscript.com/forum/index.php?showtopic=89358&hl=) doesn't support colouring, but I found (what appears to be) a similar discussion here:

http://www.autoit.de/index.php?page=Thread&threadID=11217

Seems to be working as desired with a couple of modifications:

;====================================================================================================
; Function Name: _GUICtrlRichEdit_SetFontColor
; Description:    Select the text color
; Parameters    : $hWnd         - Handle to the control
;                 $hColor       - Color value (BGR)
;                 $iSelect      - Color entire text or selection (default)
; Return values : True on success, otherwise False
; Author        : Yoan Roblet (Arcker)
; Rewritten     : grham
; Notes         :
;====================================================================================================
;
Func _GUICtrlRichEdit_SetFontColor($hWnd, $hColor, $iSelec = True)
    Local $tcharformat = DllStructCreate($tagCHARFORMAT2)
    DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_COLOR)
    DllStructSetData($tcharformat, 6, $hColor)
    Local $iSelec2 = $SCF_ALL
    If $iSelec Then $iSelec2 = $SCF_SELECTION
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec2, DllStructGetPtr($tcharformat))
EndFunc   ;==>_GUICtrlRichEdit_SetFontColor

;====================================================================================================
; Function Name: _GUICtrlRichEdit_SetLineLastColor
; Description:    Set the text colour of the previously enterred line.
; Parameters    : $hWnd         - Handle to the control
;                 $hColor       - Color value (BGR)
; Return values : 
; Author        : 
; Rewritten     : 
; Notes         :
;====================================================================================================
;
Func _GUICtrlRichEdit_SetLineLastColor($h_RichEdit,$Color)
    Local $LineStart = _GUICtrlRichEdit_GetFirstCharPosOnLine($h_RichEdit,_GUICtrlRichEdit_GetLineCount($h_RichEdit))
    Local $LineLength = _GUICtrlRichEdit_GetLineLength($h_RichEdit,$LineStart)
    
    _GUICtrlRichEdit_SetSel($h_RichEdit, $LineStart,$LineStart+$LineLength)
    _GUICtrlRichEdit_SetFontColor($h_RichEdit,$Color,True)
    _GUICtrlRichEdit_Deselect($h_RichEdit)
    
EndFunc

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