?
Solved

Richedit and Colors

Posted on 1998-04-16
10
Medium Priority
?
720 Views
Last Modified: 2008-02-01
I am trying to use a Richedit Control with colored text . I have used colors for the text , using the CHARFORMAT structure , but I do not know how to set the background color of a chat . Warning : Not the background of the whole control
0
Comment
Question by:WxW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1184343
I suspect that is not possible.  I don't know much about richedit controls.  But it is not possible (that I know of--and I have looked) to set the background color in Microsoft Word (except the entire background)  And I doubt that richedit controls would have features that Word doesn't.
0
 
LVL 23

Accepted Solution

by:
chensu earned 300 total points
ID: 1184344
You can set the background color of a character with Rich Edit 2.0.

The CHARFORMAT2 structure contains information about character formatting in a rich edit control. CHARFORMAT2 is a Rich Edit version 2.0 extension of the CHARFORMAT structure. Rich Edit 2.0 allows you to use either structure with the EM_GETCHARFORMAT and EM_SETCHARFORMAT messages.

typedef struct _charformat2 {
    UINT        cbSize;
    _WPAD       _wPad1;
    DWORD       dwMask;
    DWORD       dwEffects;
    LONG        yHeight;
    LONG        yOffset;
    COLORREF    crTextColor;
    BYTE        bCharSet;
    BYTE        bPitchAndFamily;
    WCHAR       szFaceName[LF_FACESIZE];
    _WPAD       _wPad2;
    WORD        wWeight;
    SHORT       sSpacing;
    COLORREF    crBackColor;
    LCID        lcid;
    DWORD       dwReserved;
    SHORT       sStyle;
    WORD        wKerning;
    BYTE        bUnderlineType;
    BYTE        bAnimation;
    BYTE        bRevAuthor;
    BYTE        bReserved1;
} CHARFORMAT2;

0
 
LVL 6

Author Comment

by:WxW
ID: 1184345
Yes and why this code won't work ?

CharFormat.cbSize = sizeof(CharFormat);
::SendMessage(hW,EM_GETCHARFORMAT,false,(LPARAM)&CharFormat);
CharFormat.cbSize = sizeof(CharFormat);
ChararFormat.dwMask |= CFM_COLOR;
CharFormat.dwEffects &= ~(CFE_AUTOCOLOR);
CharFormat.yHeight = 0;
CharFormat.yOffset = 0;
CharFormat.crTextColor = GetRGB(TheColor1);
CharFormat.bCharSet = 0;
CharFormat.bPitchAndFamily = 0;
CharFormat.wWeight = 0;
CharFormat.sSpacing = 0;
CharFormat.crBackColor = GetRGB(TheColor2);
CharFormat.lcid = 0;
CharFormat.dwReserved = 0;
CharFormat.sStyle = 0;
CharFormat.wKerning = 0;
CharFormat.bUnderlineType = 0;
CharFormat.bAnimation = 0;
CharFormat.bRevAuthor = 0;
::SendMessage(hW,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&CharFormat);

Note the hW = richedit handle , GetRGB just a macro returning COLORREF values

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:chensu
ID: 1184346
What do you mean by "this code won't work"? Compiling error or something else?

Make sure you are using CHARFORMAT2 and cbSize is sizeof(CHARFORMAT2).

0
 
LVL 6

Author Comment

by:WxW
ID: 1184347
I just mean that there are no compiling errors , but the Edit Control does not accept and recognize my color values . It does not recognize not only the BackGround color , but also the ForeGround . I believe that my code lacks a statement , but I do not know what
0
 
LVL 23

Expert Comment

by:chensu
ID: 1184348
Are you using Rich Edit 2.0 (RichEd20.DLL)?
0
 
LVL 6

Author Comment

by:WxW
ID: 1184349
I discovered that I had not created a "Richedit20A" class , but a RichEdit 1.0 . However I have another problem now : The RichEdit I create seems inactive , and no-messages processing . Is there any special call I must use except the standard RichEdit 1.0 functions and messages ?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1184350
Did you call the LoadLibrary function to load the RICHED20.DLL before creating a rich edit control?
0
 
LVL 6

Author Comment

by:WxW
ID: 1184351
Thanks chensu . That was the problem . I have read also in the MSDN . If you can solve me the two more problems .... why the EM_SETSEL -1,-1 does not do the same like RichEdit 1.0 , but rather selects all the text . And b) , I want no-horizontal scroll bar . I want line breaking .Thanks a lot !!
0
 
LVL 23

Expert Comment

by:chensu
ID: 1184352
1. Do you send the EM_SETSEL message with wParam == -1 and lParam == -1? If so, I don't know why. According to the documentation, "If nStart is –1, any current selection is removed.".

2. Remove the WS_HSCROLL style of the Rich Edit control.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question