NEW RichEdit QUESTION!

This is a discussion on NEW RichEdit QUESTION! within the Windows Programming forums, part of the Platform Specific Boards category; I know how to set background and text colors(and font faces) in RichEdit controls. I can't figure out how to ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question NEW RichEdit QUESTION!

    I know how to set background and text colors(and font faces) in RichEdit controls. I can't figure out how to set only certain words to a specific color. Can anyone help, please?

    Thanks,
    Matt U.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post Please Reply!

    Someone please at least give me some links. I can't find anything I need at MSDN, except for each message. I know I need to get the text range with EM_GETTEXTRANGE, but I tried and it didn't work. I am trying to highlight HTML syntax(ex. <, >, and </). I want it to do it as soon as a <, >, or </ is entered into the RichEdit Control.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Well, at the risk of appearing once more as blatant self-publicist, you could try the example on my wee humble website; but if you are serious about fast syntax highlighting a web search on the subject should reveal some useful info on using streams to ferry info to and from a richedit control.

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question URL...

    What's the URL to you website?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326

    http://www.foosyerdoos.fsnet.co.uk

    It was in his profile...

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Sorry, it was late...

    http://www.foosyerdoos.fsnet.co.uk

    or you could just click the 'www' button beneath a post or click the 'profile button' and get it from the opened page.

  7. #7
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Ok, I checked it out, but...

    Ken's site had a lot of good examples. They helped me in some of the things I needed, but one thing. I didn't see anything about coloring certain chars a certain color. For example, if I entered: H it would be the font color the user selected(I got that done), but if I type <, >, or </ I want it to be RGB(200, 0, 0). How would I do that?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Select the required text and then format it:
    Code:
    CHARFORMAT cf;
    ZeroMemory(&cf,sizeof(cf));
    cf.cbSize=sizeof(cf);
    lstrcpy(cf.szFaceName,TEXT("Arial"));
    cf.bCharSet=ANSI_CHARSET;
    cf.bPitchAndFamily=FF_ROMAN;
    //bold, italic, underlined and coloured red. Height also valid
    cf.dwMask=CFM_COLOR|CFM_SIZE|CFM_FACE|CFM_EFFECTS;
    cf.dwEffects=CFE_BOLD|CFE_ITALIC|CFE_UNDERLINE;
    cf.crTextColor=RGB(200,0,0);
    cf.yHeight=200;
    
    //select all the current text for formatting
    CHARRANGE cr={0,-1};  
    SendMessage(hwndRichEdit,EM_EXSETSEL,0,(LPARAM)&cr);
    //let the cntrl know about it
    SendMessage(hwndRichEdit,EM_SETCHARFORMAT,SCF_WORD|SCF_SELECTION,(LPARAM)&cf);
    Formats everything. If you change the CHARRANGE values to the text you wish to change, that should do it. You can use the EM_EXGETSEL to fill a CHARRANGE struct with the current selected text range.

  9. #9
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post About EM_EXGETSEL

    I tried using EM_EXGETSEL, but I didn't know how. But that should work. Example, please?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Code:
    CHARRANGE cr;
    SendMessage(hwndRichEdit,EM_EXGETSEL,0,(LPARAM)&cr);
    cr should now have the current selection range.

  11. #11
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Is This Correct?

    CHARRANGE cr;

    SendMessage(hRichEd, EM_EXGETSEL, 0, (LPARAM) &cr);

    CHARFORMAT cf;
    ZeroMemory(&cf, sizeof(cf));

    cf.cbSize = sizeof(cf);
    cf.dwMask = CFM_FACE | CFM_COLOR;

    SendMessage(hRichEd, EM_EXSETSEL, 0, (LPARAM) &cr);

    SendMessage(hRichEd, EM_SETCHARFORMAT, (WPARAM) SCF_WORD | SCF_SELECTION, (LPARAM) &cf);

    Is That Correct? I think it will work, but I want to color < and > as the user inputs them. Will this code do that?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try it and see.

    But don't forget to set your colour selection:

    cf.crTextColor=RGB(200,0,0);

    before sending the EM_SETCHARFORMAT message.

  13. #13
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490
    I am getting this now. Now I have another question. How do I handle the EN_CHANGE message for a rich edit with an ID of 200? That should check input and color it as it comes in. I just need how to set it up.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. Problems with my richedit...
    By tyouk in forum Windows Programming
    Replies: 2
    Last Post: 11-02-2003, 03:57 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. RichEdit Problem
    By dirkduck in forum Windows Programming
    Replies: 0
    Last Post: 07-24-2003, 05:50 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21