BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RichEdit background colour
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
David Ayre
Guest





PostPosted: Wed Apr 12, 2006 4:03 pm    Post subject: RichEdit background colour Reply with quote



Hi,

I am using a TRichEdit component and use the following code to add lines to it:-

void __fastcall TAudit::AddLine(TRichEdit *RE,const AnsiString &Text,int iSize,const AnsiString &Name,bool IsBold)
{
//Add line to RichEdit
RE->SelStart = RE->GetTextLen();
RE->SelLength = 0;
RE->SelAttributes->Name = Name;
RE->SelAttributes->Size = iSize;
TFontStyles Styles = RE->SelAttributes->Style;
if(IsBold)Styles << fsBold;
else Styles >> fsBold;
RE->SelAttributes->Style = Styles;
RE->SelText = (Text + "\r\n");
}

This works well, but is it possible to set the background colour
of the line in this routine. I would like lines to be alternately
white and moneygreen.

Thanks,

David Ayre
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Apr 12, 2006 6:03 pm    Post subject: Re: RichEdit background colour Reply with quote



"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:443d174f$1 (AT) newsgroups (DOT) borland.com...

Quote:
This works well, but is it possible to set the background
colour of the line in this routine.

The ability to specify per-character background colors was introduced in
RichEdit v2.0. TRichEdit uses v1.0 instead. The only way to use RichEdit
v2.0+ features in TRichEdit is if you are running your code under XP or
higher. Those OS versions have RichEdit v3.0/4.0 installed, and internally
map all RichEdit v1.0 controls to that version. The code still thinks that
it is using v1.0, but it can send v3.0+ commands to it.

Otherwise, you will have to stop using TRichEdit entirely and write/find a
third-party component that uses the newer RichEdit versions. Have a look at
Robert Dunn's TaeRichEdit component
(http://home.att.net/~robertdunn/Yacs.html) and his articles on RichEdit
controls.


Gambit
Back to top
David Ayre
Guest





PostPosted: Wed Apr 12, 2006 8:03 pm    Post subject: Re: RichEdit background colour Reply with quote



"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

The ability to specify per-character background colors was introduced in
RichEdit v2.0. TRichEdit uses v1.0 instead. The only way to use RichEdit
v2.0+ features in TRichEdit is if you are running your code under XP or
higher. Those OS versions have RichEdit v3.0/4.0 installed, and internally
map all RichEdit v1.0 controls to that version. The code still thinks that
it is using v1.0, but it can send v3.0+ commands to it.


Thanks Remy,

Nothing's ever simple, is it?
I am using BDS 2006 and running Win XP Prof. Where can I find
the commands that will allow me to use the other features of
RichEdit 3.0/4.0?
Or do you think it would be better to change over to the
taeRichEdit component?

Cheers,

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Apr 12, 2006 11:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:443d4a23$1 (AT) newsgroups (DOT) borland.com...

Quote:
Where can I find the commands that will allow me to use
the other features of RichEdit 3.0/4.0?

MSDN, where else? ;-)

Specifically, for this particular issue, use the EM_SETCHARFORMAT2 message
to assign the colors.


Gambit
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 9:03 am    Post subject: Re: RichEdit background colour Reply with quote

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:443d4a23$1 (AT) newsgroups (DOT) borland.com...

Where can I find the commands that will allow me to use
the other features of RichEdit 3.0/4.0?

MSDN, where else? ;-)

Specifically, for this particular issue, use the EM_SETCHARFORMAT2 message
to assign the colors.


Gambit


Thanks Remy,


I'll see what I can find.

Cheers,

David
Back to top
Antonio Felix
Guest





PostPosted: Thu Apr 13, 2006 12:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
Quote:

I tried MSDN but couldn't find anything on RichEdit. It's
probably me but I think it is one of the most unhelpful
websites I have seen. I tried phoning them but got nowhere
with that either.
Could you tell me how I should use EM_SETCHARFORMAT2 please.


Hi David,

Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

HTH
Antonio
Back to top
Antonio
Guest





PostPosted: Thu Apr 13, 2006 12:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"Antonio Felix" <nomail (AT) nm (DOT) pt> wrote:
Quote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:

I tried MSDN but couldn't find anything on RichEdit. It's
probably me but I think it is one of the most unhelpful
websites I have seen. I tried phoning them but got nowhere
with that either.
Could you tell me how I should use EM_SETCHARFORMAT2 please.


Hi David,

Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

HTH
Antonio

David,

Rich Edit 2.0 allows you to use either structure, CHARFORMAT &
CHAFORMAT2, with the EM_GETCHARFORMAT and EM_SETCHARFORMAT messages.

Br
Antonio
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 12:03 pm    Post subject: Re: RichEdit background colour Reply with quote

I tried MSDN but couldn't find anything on RichEdit. It's
probably me but I think it is one of the most unhelpful
websites I have seen. I tried phoning them but got nowhere
with that either.
Could you tell me how I should use EM_SETCHARFORMAT2 please.

Cheers,

David

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
Quote:

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:443d4a23$1 (AT) newsgroups (DOT) borland.com...

Where can I find the commands that will allow me to use
the other features of RichEdit 3.0/4.0?

MSDN, where else? ;-)

Specifically, for this particular issue, use the EM_SETCHARFORMAT2 message
to assign the colors.


Gambit


Thanks Remy,

I'll see what I can find.

Cheers,

David
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 2:03 pm    Post subject: Re: RichEdit background colour Reply with quote

Thanks Antonio,

That's great.

Cheers,

David


"Antonio" <nomail (AT) nm (DOT) pt> wrote:
Quote:

"Antonio Felix" <nomail (AT) nm (DOT) pt> wrote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:

I tried MSDN but couldn't find anything on RichEdit. It's
probably me but I think it is one of the most unhelpful
websites I have seen. I tried phoning them but got nowhere
with that either.
Could you tell me how I should use EM_SETCHARFORMAT2 please.


Hi David,

Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

HTH
Antonio

David,

Rich Edit 2.0 allows you to use either structure, CHARFORMAT &
CHAFORMAT2, with the EM_GETCHARFORMAT and EM_SETCHARFORMAT messages.

Br
Antonio
Back to top
Antonio Felix
Guest





PostPosted: Thu Apr 13, 2006 3:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
Quote:


Hi David,

Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

HTH
Antonio

David,

Rich Edit 2.0 allows you to use either structure, CHARFORMAT &
CHAFORMAT2, with the EM_GETCHARFORMAT and EM_SETCHARFORMAT messages.

Tried the following:-

CHARFORMAT *fmt = new CHARFORMAT();
fmt->cbSize = sizeof(fmt);
fmt->dwMask = CFM_BACKCOLOR;
fmt->crBackColor = clMoneyGreen;
RE->Perform(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)fmt);
delete fmt;

and I get an error message saying that there is no crBackColor
in CHARFORMAT.
If I replace CHARFORMAT with CHARFORMAT2 it says that there is
ambiguity between CHARFORMAT2A and RichEdit::CHARFORMAT2A

What am I doing wrong?

Cheers,

David

Hi David,

I'm away from my Dev machine, but try to use the explicit
qualifier for the namespace.

The richedit.hpp defines;
namespace Richedit

so you may use (untested):

Richedit::CHARFORMAT2 *fmt = new CHARFORMAT2();

HTH
Antonio
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 3:03 pm    Post subject: Re: RichEdit background colour Reply with quote

Quote:
Hi David,

Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

HTH
Antonio

David,

Rich Edit 2.0 allows you to use either structure, CHARFORMAT &
CHAFORMAT2, with the EM_GETCHARFORMAT and EM_SETCHARFORMAT messages.

Tried the following:-

CHARFORMAT *fmt = new CHARFORMAT();
fmt->cbSize = sizeof(fmt);
fmt->dwMask = CFM_BACKCOLOR;
fmt->crBackColor = clMoneyGreen;
RE->Perform(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)fmt);
delete fmt;

and I get an error message saying that there is no crBackColor
in CHARFORMAT.
If I replace CHARFORMAT with CHARFORMAT2 it says that there is
ambiguity between CHARFORMAT2A and RichEdit::CHARFORMAT2A

What am I doing wrong?

Cheers,

David
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 4:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
Quote:

Hi David,

I'm away from my Dev machine, but try to use the explicit
qualifier for the namespace.

The richedit.hpp defines;
namespace Richedit

so you may use (untested):

Richedit::CHARFORMAT2 *fmt = new CHARFORMAT2();

HTH
Antonio

Thanks Antonio,

I'll give that a try.

David

Hi Antonio,

I tried that and it now compiles. This is my code which I use to
add a line to the RichEdit:-

void __fastcall TAudit::AddLine(TRichEdit *RE,const AnsiString &Text,int iSize,const AnsiString &Name,bool IsBold)
{
//Add line to RichEdit
Richedit::CHARFORMAT2 *fmt = new Richedit::CHARFORMAT2();
fmt->cbSize = sizeof(fmt);
fmt->dwMask = CFM_BACKCOLOR;
fmt->crBackColor = (TColor)clRed;
RE->SelStart = RE->GetTextLen();
RE->SelLength = 0;
RE->SelAttributes->Name = Name;
RE->SelAttributes->Size = iSize;
TFontStyles Styles = RE->SelAttributes->Style;
if(IsBold)Styles << fsBold;
else Styles >> fsBold;
RE->SelAttributes->Style = Styles;
RE->Perform(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)fmt);
RE->SelText = (Text + "\r\n");
delete fmt;
}

The additions to set the backgrount colour does nothing. For
this test I'm just setting the background to clRed. When I get
it to work I'll add the new colour to the routine parameters so
that it can be different for each line.
Everything except the background colour works OK.
Any ideas?

Cheers,

David
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 4:03 pm    Post subject: Re: RichEdit background colour Reply with quote

Quote:
Hi David,

I'm away from my Dev machine, but try to use the explicit
qualifier for the namespace.

The richedit.hpp defines;
namespace Richedit

so you may use (untested):

Richedit::CHARFORMAT2 *fmt = new CHARFORMAT2();

HTH
Antonio

Thanks Antonio,

I'll give that a try.

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Apr 13, 2006 6:03 pm    Post subject: Re: RichEdit background colour Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:443e2abb$1 (AT) newsgroups (DOT) borland.com...

Quote:
I tried MSDN but couldn't find anything on RichEdit.

Did you use the search engine? There is a whole chapter on RichEdits. Took
me about 5 seconds to find:


http://search.msdn.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=rich+edit+controls

The first item on the results list is this:

Rich Edit Controls (Windows Explorer and Controls)

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/RichEdit/RichEditControls.asp

Navigating into the "Messages" section of that chapter, you find this:

EM_SETCHARFORMAT Message

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_setcharformat.asp

Which then leads you to this:

CHARFORMAT2 Structure

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

crBackColor
Background color. To use this member, set the CFM_BACKCOLOR flag in
the dwMask member. This member is ignored if the CFE_AUTOBACKCOLOR character
effect is specified.

Quote:
It's probably me but I think it is one of the most unhelpful websites I
have seen.


MSDN works just fine, you just have to be comfortable with its search
engine.

Quote:
I tried phoning them but got nowhere with that either.

That was a waste of time.


Gambit
Back to top
David Ayre
Guest





PostPosted: Thu Apr 13, 2006 6:03 pm    Post subject: Re: RichEdit background colour Reply with quote

I've cracked it.
fmt->cbSize = sizeof(fmt);
Should have been:-
fmt->cbSize = sizeof(Richedit::CHARFORMAT2);

Now it works.

Thanks for all the help.

David


Quote:

Hi Antonio,

I tried that and it now compiles. This is my code which I use to
add a line to the RichEdit:-

void __fastcall TAudit::AddLine(TRichEdit *RE,const AnsiString &Text,int iSize,const AnsiString &Name,bool IsBold)
{
//Add line to RichEdit
Richedit::CHARFORMAT2 *fmt = new Richedit::CHARFORMAT2();
fmt->cbSize = sizeof(fmt);
fmt->dwMask = CFM_BACKCOLOR;
fmt->crBackColor = (TColor)clRed;
RE->SelStart = RE->GetTextLen();
RE->SelLength = 0;
RE->SelAttributes->Name = Name;
RE->SelAttributes->Size = iSize;
TFontStyles Styles = RE->SelAttributes->Style;
if(IsBold)Styles << fsBold;
else Styles >> fsBold;
RE->SelAttributes->Style = Styles;
RE->Perform(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)fmt);
RE->SelText = (Text + "\r\n");
delete fmt;
}

The additions to set the backgrount colour does nothing. For
this test I'm just setting the background to clRed. When I get
it to work I'll add the new colour to the routine parameters so
that it can be different for each line.
Everything except the background colour works OK.
Any ideas?

Cheers,

David
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.