Solved

Richedit and Colors

Posted on 1998-04-16
10
713 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 100 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

626 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