Thread: Yet another question

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    36

    Talking Yet another question

    Okay okay, if I ask too much, tell me so *g* but understand it more as a compliment, if here weren't so many peeps who actually can HELP, I wouldn't ask that much


    well anyway, here's my next problem:

    The following function adds a string to the contents of a rich edit:

    Code:
    BOOL OutputLine(HWND hEdit, LPSTR pszAddText, BYTE red, BYTE green, BYTE blue)
    {
        static CHARFORMAT2 charFormat;
    
        char pszText[1000];
        DWORD dwBufferSize;
        int firstChar;
        int currentLine;
    
        dwBufferSize = GetWindowTextLength(hEdit)+1;
    
        GetWindowText(hEdit, pszText, dwBufferSize);
        strcat(pszText, pszAddText);
        SetWindowText(hEdit, pszText);
    
        currentLine = (INT) SendMessage(hEdit, EM_GETLINECOUNT, 0, 0); currentLine-=2;
        firstChar = (INT) SendMessage(hEdit, EM_LINEINDEX, (WPARAM) currentLine, 0);
    
        SendMessage(hEdit, EM_SETSEL, (WPARAM) firstChar, (LPARAM) -1);
    
        ZeroMemory(&charFormat,sizeof(CHARFORMAT2));
        charFormat.cbSize = sizeof(CHARFORMAT); charFormat.dwMask = CFM_COLOR;
        charFormat.crTextColor = RGB(red,green,blue);
        SendMessage(hEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION | SCF_WORD, (LPARAM) &charFormat);
    
        SendMessage( hEdit, EM_LINESCROLL, 0, 1 );  
      return 1;
    }
    I call it for example so:

    Code:
        sprintf(pszTemp, "Temp content: %d\r\n", test);
        OutputLine(hEditOutput, pszTemp,0,0,255);

    well and it should also set the color of the newly added text.

    The thing is, the string is correctly added and scrolled into view, but the thing with the color doesn't work quite the way I wanted it to be. It does set the added line of text in the color I pass to the function, but everything else (including colored lines I added before) goes black again. (I hope this was described in an understandable way.)

    I don't really get why it behaves so

    PrivatePanic
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    In my experience this is just the way it goes. You can subclass the edit control and do everything manually. I'm not going to go into too much detail because I've seen this same question on the boards before. So try and search the boards for some answers.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    In my experience this is just the way it goes.
    Well there must be a way to write colored text into a rich edit that stays colored I saw it often enough. Maybe this attempt by me is completely the wrong direction; then I'd appreciate a hint for the correct attempt.

    You can subclass the edit control and do everything manually.
    Somehow I believe there must be an easier way, if there is none, okay. If someone DOES know of an easier solution, gimme

    I'm not going to go into too much detail because I've seen this same question on the boards before. So try and search the boards for some answers.
    Well you have to trust me I did so. In fact, I searched the topics from the beginning on (this are by the way over 45 pages of topics) and found no thread that helped me really. If I found one, I wouldn't ask. So please help me if you know how to... or point me to a tutorial or something similar. I'm really NOT the kind of person who first asks, and THEN uses the search button. If I really missed a thread in this board that contains the answer to my question, I apologize and promise to read it. Just throw the link to it in my general direction

    Anyone else have a solution for me?

    PrivatePanic
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    eh? I'm sure you looked, but I'm even more sure that I saw this exact same problem on the boards not too long ago. That should help.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    Yes, of course I looked. And I actually also found the thread you're pointing me to here.

    But how should this thread help me?

    See - I'm NOT trying to do syntax hilighting here, nor anything similar, I don't want to color single words on the fly, I just want to add, say, a blue line of text to the rich edit without turning the lines, that are allready there, black again (and that is what happens)

    So how should the information of the thread u showed me (which I knew allready, actually) help me with that

    Well, someone mentioned in that thread one could add rtf syntax formatting; if I knew how that can be done, maybe this would help me... I just could add {\color(red,green,blue or sumthing like that and then the new line. That'd be cool.

    And don't get me wrong, maybe I don't make myself clear enough cause I'm no native English speaker (writer ) so plz don't be upset, but actually try to help
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM