Solved

Richedit and Colors

Posted on 1998-04-16
10
684 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now