hello again,
can any at all help my speed up this loop ive been at it for weeks on end trying different methods , functions ... but i just cant get it to work properly and faster because the problem is that as the buffer gets bigger its takes longer to go through the loop and it pauses the program until its done :'(

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 :-

char szIntro[150] = "(0,0,225)# Welcome to Hyper Chat v.1 (127,127,127)-\r\n(255,0,0)# Finished Initializing HC GUI. (127,127,127)-\r\n\r\n";

basically it prints out to a RICHEDIT the formatted text its like mIRC scripting but mine just sucks

if there is any headers or any functions that already do this then please tell me

thx alot in advance