Solved

Richedit and Colors

Posted on 1998-04-16
10
677 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 23

Expert Comment

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

Author Comment

by:WxW
Comment Utility
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
Comment Utility
Did you call the LoadLibrary function to load the RICHED20.DLL before creating a rich edit control?
0
 
LVL 6

Author Comment

by:WxW
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
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.

763 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

6 Experts available now in Live!

Get 1:1 Help Now