haputanlas Posted January 14, 2011 Share Posted January 14, 2011 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. Link to comment Share on other sites More sharing options...
haputanlas Posted January 15, 2011 Author Share Posted January 15, 2011 (edited) 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 January 15, 2011 by haputanlas Link to comment Share on other sites More sharing options...
Zedna Posted January 15, 2011 Share Posted January 15, 2011 #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 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted January 15, 2011 Share Posted January 15, 2011 (edited) 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 January 15, 2011 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
haputanlas Posted January 15, 2011 Author Share Posted January 15, 2011 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. Link to comment Share on other sites More sharing options...
Zedna Posted January 15, 2011 Share Posted January 15, 2011 This was it. Thanks, that function just helped make the entire UDF make sense.Also notice I added _GUICtrlRichEdit_Destroy($Edit1) It's very important because without it Autoit3.exe process was still running after closing GUIand later after more tries it blocked CPU. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
haputanlas Posted January 16, 2011 Author Share Posted January 16, 2011 Also notice I added _GUICtrlRichEdit_Destroy($Edit1) It's very important because without it Autoit3.exe process was still running after closing GUIand later after more tries it blocked CPU.Yeah, I figured that one out pretty quickly after I tried the code.Thanks though! 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