Code:
void OutputToDisplay(char *p)
{
char R[3],G[3],B[3];
szBuffer2.append(p);
SetWindowText((HWND)hEditDisplay, szBuffer2.c_str());
//set applicable character formats.
CHARFORMAT cf;
ZeroMemory(&cf,sizeof(cf));
cf.cbSize=sizeof(cf);
lstrcpy(cf.szFaceName,TEXT("Verdana"));
cf.bCharSet=ANSI_CHARSET;
cf.bPitchAndFamily=FF_ROMAN;
cf.dwMask=CFM_COLOR|CFM_SIZE|CFM_FACE|CFM_EFFECTS;
cf.dwEffects=0;
cf.crTextColor=RGB(0,180,255);
cf.yHeight=150;
//select all the current text for formatting
CHARRANGE cr={0,-1};
SendMessage(hEditDisplay,EM_EXSETSEL,0,(LPARAM)&cr);
//let the cntrl know about it
SendMessage(hEditDisplay,EM_SETCHARFORMAT,SCF_WORD|SCF_SELECTION,(LPARAM)&cf);
int len = strlen(szBuffer2.c_str());
char data[len];
strcpy(data,szBuffer2.c_str());
int count = 0;
int countc = 0,countcc = 0;
int iOCcount = 0,iCCcount = 0;
int iTotalClength = 0;
int clength = 0;
for(int i = 0;i<strlen(data);i++)
{
if(data[i] == '\n'){
count++;
}
if(data[i] == C_COLOR){
int counter = 1;
int l = 0,m = 0,n = 0;
if(data[i+1] == '('){
for(int j=i;j<i+14;j++){
if(data[j] == ')'){
clength = j-i;
}
}
SendMessage((HWND)hEditDisplay, EM_SETSEL, (i-count)-(iCCcount+iTotalClength), ((i-count)-(iCCcount+iTotalClength))+(clength+1));
SendMessage((HWND)hEditDisplay, EM_REPLACESEL, 0, (LPARAM)"");
for(int k=i+1;k<(clength+i);k++){
if(data[k] != '('){
if((data[k] != ')') & (counter <= 3)){
if(data[k] != ','){
switch(counter){
case 1:
{
R[l] = data[k];
l++;
}
break;
case 2:
{
G[m] = data[k];
m++;
}
break;
case 3:
{
B[n] = data[k];
n++;
}
break;
}
}else{
counter++;
}
}else{
k = clength;
}
}
}
if((R != "") & (G != "") & (B != "")){
//set applicable character formats.
ZeroMemory(&cf,sizeof(cf));
cf.cbSize=sizeof(cf);
lstrcpy(cf.szFaceName,TEXT("Verdana"));
cf.bCharSet=ANSI_CHARSET;
cf.bPitchAndFamily=FF_ROMAN;
cf.dwMask=CFM_COLOR|CFM_SIZE|CFM_FACE|CFM_EFFECTS;
cf.dwEffects=0;
cf.crTextColor=RGB(atoi(R),atoi(G),atoi(B));
cf.yHeight=150;
CHARRANGE cr1={(i-count)-(iCCcount+iTotalClength),strlen(data)};
SendMessage(hEditDisplay,EM_EXSETSEL,0,(LPARAM)&cr1);
SendMessage(hEditDisplay,EM_SETCHARFORMAT,SCF_WORD|SCF_SELECTION,(LPARAM)&cf);
}
}
iTotalClength += clength;
iCCcount++;
}
}
SetFocus(hEditDisplay);
SendMessage((HWND)hEditDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
SendMessage((HWND)hEditDisplay, EM_SCROLLCARET, 0, 0);
SetFocus(hEditMessage);
}
the sring that is sent to it is :-