Cheez Posted September 16, 2009 Share Posted September 16, 2009 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. Link to comment Share on other sites More sharing options...
Zedna Posted September 16, 2009 Share Posted September 16, 2009 Definitely look at Richedit UDF in Examples forum. It has all that functionality. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Cheez Posted September 16, 2009 Author Share Posted September 16, 2009 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: expandcollapse popup;==================================================================================================== ; 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 Link to comment Share on other sites More sharing options...
Cheez Posted September 16, 2009 Author Share Posted September 16, 2009 Oops, wasn't applying to the correct line. Local $LineStart = _GUICtrlRichEdit_GetFirstCharPosOnLine($h_RichEdit,_GUICtrlRichEdit_GetLineCount($h_RichEdit) - 1) That works flawlessly for everything other than the first line for whatever reason. Hope that's useful to somebody. Sorry can't edit post. Link to comment Share on other sites More sharing options...
Zedna Posted September 17, 2009 Share Posted September 17, 2009 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:There are more RichEdit UDFs on the forum. Some of them support also coloring. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now