 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
David Ayre Guest
|
Posted: Wed Apr 12, 2006 4:03 pm Post subject: RichEdit background colour |
|
|
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
|
Posted: Wed Apr 12, 2006 6:03 pm Post subject: Re: RichEdit background colour |
|
|
"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
|
Posted: Wed Apr 12, 2006 8:03 pm Post subject: Re: RichEdit background colour |
|
|
"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
|
Posted: Wed Apr 12, 2006 11:03 pm Post subject: Re: RichEdit background colour |
|
|
"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
|
Posted: Thu Apr 13, 2006 9:03 am Post subject: Re: RichEdit background colour |
|
|
"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
|
|
| Back to top |
|
 |
Antonio Guest
|
Posted: Thu Apr 13, 2006 12:03 pm Post subject: Re: RichEdit background colour |
|
|
"Antonio Felix" <nomail (AT) nm (DOT) pt> wrote:
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
|
Posted: Thu Apr 13, 2006 12:03 pm Post subject: Re: RichEdit background colour |
|
|
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
|
Posted: Thu Apr 13, 2006 2:03 pm Post subject: Re: RichEdit background colour |
|
|
Thanks Antonio,
That's great.
Cheers,
David
"Antonio" <nomail (AT) nm (DOT) pt> wrote:
|
|
| Back to top |
|
 |
Antonio Felix Guest
|
Posted: Thu Apr 13, 2006 3:03 pm Post subject: Re: RichEdit background colour |
|
|
"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote:
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
|
Posted: Thu Apr 13, 2006 3:03 pm Post subject: Re: RichEdit background colour |
|
|
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
|
Posted: Thu Apr 13, 2006 4:03 pm Post subject: Re: RichEdit background colour |
|
|
"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
|
Posted: Thu Apr 13, 2006 4:03 pm Post subject: Re: RichEdit background colour |
|
|
| 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
|
|
| Back to top |
|
 |
David Ayre Guest
|
Posted: Thu Apr 13, 2006 6:03 pm Post subject: Re: RichEdit background colour |
|
|
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 |
|
 |
|
|
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
|
|