Sign in to follow this  
Followers 0
kor

cannot get _GuiCtrlRichEdit_AppendText to work right

7 posts in this topic

#1 ·  Posted (edited)

Sample

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Global $oGUI = GUICreate("test", 300, 300)
GUISetState(@SW_SHOW)

_CreateLogWindow($oGUI, 20, 20, 200, 200)
For $i = 0 To 3
    _LogMessage($i, True)
    Sleep(50)
Next
For $n = 0 To 3
    _LogMessage($n)
    Sleep(50)
Next

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CreateLogWindow(ByRef $oGUI, $iLeft = 0, $iTop = 0, $iWidth = 0, $iHeight = 0)
    Global $cLogWindow = _GUICtrlRichEdit_Create($oGUI, "", $iLeft, $iTop, $iWidth, $iHeight, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_READONLY))
    _GUICtrlRichEdit_SetBkColor($cLogWindow, 0xFFFFFF)
EndFunc   ;==>_CreateLogWindow

Func _LogMessage($sText, $bError = False)
    _GUICtrlRichEdit_AppendText($cLogWindow, @CR & $sText)
    _GUICtrlRichEdit_SetSel($cLogWindow, _GUICtrlRichEdit_GetFirstCharPosOnLine($cLogWindow), -1, True)
    If $bError = False Then _GUICtrlRichEdit_SetCharColor($cLogWindow, 0)
    If $bError = True Then _GUICtrlRichEdit_SetCharColor($cLogWindow, 255)
    Sleep(50)
EndFunc   ;==>_LogMessage

What I'm trying to do is get rid of that space at the very top of the richedit. The line feed at the very top.

I've tried everything I can think of to get rid of it but nothing is working.

If I remove the @CR from the append text then for some reason everything turns into a single line and doesn't work right.

Edited by kor

Share this post


Link to post
Share on other sites



Normally you would put the line feed at the END of the line, not at the beginning of it.

_GUICtrlRichEdit_AppendText($hRichEdit, "Line " & $i & @CR)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry, please look again. Not sure how but I pasted the wrong code. What is there now is the correct sample.

I've tried to put the line feed at the end, but if you use the correct code sample you will see it messes up the color text.

Edited by kor

Share this post


Link to post
Share on other sites

First, if you have an issue with a script post the script you're working on that shows the problem.

Second, properly explain what the problem is and any special circumstances that cause the problem, in this case you're coloring the text and putting the @CR at the end was causing it to be colored wrong, so you needed a way to get the text to be on separate lines, not have a blank line at the top of the RE control box, and needed the coloring to be correct. All you said was that your script was causing a blank line at the top of the RE control, NO explanation of why you coded it the way that you did.

Here's your _LogMessage function with the real fix for your coding dilemma, which corrects all 3 of your problems, not the one you stated in your first post, with the wrong script.

Func _LogMessage($sText, $bError = False)
_GUICtrlRichEdit_AppendText($cLogWindow, $sText) ; <<<<<<<< Remove the @CR from here
_GUICtrlRichEdit_SetSel($cLogWindow, _GUICtrlRichEdit_GetFirstCharPosOnLine($cLogWindow), -1, True)
If $bError = False Then _GUICtrlRichEdit_SetCharColor($cLogWindow, 0)
If $bError = True Then _GUICtrlRichEdit_SetCharColor($cLogWindow, 255)
_GUICtrlRichEdit_AppendText($cLogWindow, @CRLF) ; <<<<<<<<<< Add a CRLF here after you colored the last character, I used @CRLF because using just @CR was causing issues
Sleep(50)
EndFunc   ;==>_LogMessage

Now, see how easy it is to get help with your problem when you explain what it is you are having a problem with, and not something that had nothing whatever to do with the issue?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@BrewMan, thank you very much for the help.

The mis coloring of the text I figured I could fix myself if I could get the spacing correct which is why I just mentioned the Line Feed problem.

And sorry again for posting the wrong code. I did it quick before leaving work and just noticed it was wrong when I got home a few hours later.

Edit: Any way to get rid of the cursor bar in the RichEdit ? :D

Edited by kor

Share this post


Link to post
Share on other sites

Try _GUICtrlRichEdit_SetReadOnly()

Global $cLogWindow = _GUICtrlRichEdit_Create($oGUI, "", $iLeft, $iTop, $iWidth, $iHeight, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_READONLY))

I'm already setting the $ES_READONLY style when creating the richedit. Shouldn't that be enough?

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