int ErrorHandle::GetTextLength()
{
return SendMessage(m_hRichEdit,WM_GETTEXTLENGTH,0,0);
}
void ErrorHandle::AddText(char *Text)
{
int nLength=GetTextLength();
SendMessage(m_hRichEdit,EM_SETSEL, (WPARAM)nLength, (LPARAM)nLength);
SendMessage(m_hRichEdit,EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)Text);
}
void ErrorHandle::SetTextColor(COLORREF Color)
{
m_sCharFormat.cbSize=sizeof(CHARFORMAT);
m_sCharFormat.dwMask=CFM_COLOR;
m_sCharFormat.crTextColor=Color;
m_sCharFormat.dwEffects&=!CFE_AUTOCOLOR;
SendMessage(m_hRichEdit,EM_SETCHARFORMAT,(WPARAM)SCF_SELECTION,(LPARAM)&m_sCharFormat);
}
I call it in my code like this.
ErrorH->SetTextColor(0x00FF00);
for(i=0;i<50;i++)
ErrorH->AddText("JABOLL\n PIJ \n");
And only the first call of AddText produced greentext, rest is black;
Maybe this will solve things (haven't tested it) :
void ErrorHandle::AddText(char *Text, COLORREF Color){
int nLength;
int tLength; // total length
nLength=GetTextLength();
tLength=strlen(Text) + nLength;
SendMessage(m_hRichEdit,EM_SETSEL, (WPARAM)nLength, (LPARAM)nLength);
SendMessage(m_hRichEdit,EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)Text);
//SendMessage(m_hRichEdit,EM_SETSEL, (WPARAM)nLength, (LPARAM)tLength);
m_sCharFormat.cbSize=sizeof(CHARFORMAT);
m_sCharFormat.dwMask=CFM_COLOR;
m_sCharFormat.crTextColor=Color;
m_sCharFormat.dwEffects&= ~CFE_AUTOCOLOR;
SendMessage(m_hRichEdit,EM_SETCHARFORMAT,(WPARAM)SCF_SELECTION,(LPARAM)&m_sCharFormat);
}
Probably it will but.
I don't want to specify the color every time i want to write text.
It will be slower, so less usefull for debugging purpose.
I already have got such a function for one message colored text and i want to use function overloading for text writing functions.
I don't want to specify the color every time i want to write text.
It will be slower, so less usefull for debugging purpose.
I already have got such a function for one message colored text and i want to use function overloading for text writing functions.