GSI

MFC 에서 ListBox 에 내용을 추가 하는 코드로 테스트 해본겁니다.

void UTRACE(char* fmt...)
{
 //CString output;
 CTime time = CTime::GetCurrentTime();

 std::ostringstream outstream;
 outstream << "[" << time.GetHour() << ":" << time.GetMinute() << ":" << time.GetSecond() << "] ";

 va_list ap;            //argument pointer

 char*p; int ival; double dval;
 char pBuf[256];  // 버퍼용

 va_start(ap, fmt);        //make ap point to the final named arg
 for(p=fmt; *p; p++) {
  if(*p !='%'){
   outstream << *p;
   //putchar(*p);
   continue;
  }

  switch(*++p){
    case 'd':
     ival = va_arg(ap, int);        //get the argument and move on to the next
     outstream << ival;
     /*itoa(ival, pBuf, 10);
     for(int i=0 ; i < (int)strlen(pBuf) ; i++)
     {
      putchar(pBuf[i]);
     }*/
     break;

    case 'f':
     dval = va_arg(ap, double);        //get the argument and move on to the next
     outstream << dval;
     /*dval = atof( pBuf );
     for(int i=0 ; i < (float)strlen(pBuf) ; i++)
     {
      putchar(pBuf[i]);
     }*/
     break;

    case 's':
     sarg = va_arg(ap, const char *);        //get the argument and move on to the next
     outstream << sarg;
     break;
    case 't':
     outstream << "\t";
     break;

    default:
     outstream << *p;
     break;

  }
 }
 va_end(ap);

 g_pDebugListBox->AddString( outstream.str().c_str() );
 g_pDebugListBox->SetCurSel( g_pDebugListBox->GetCount()-1 );

// 여기에서 콘솔 모드면 아래 코드를 적용하면 될듯 하다.
 memset( pBuf, 0, sizeof(char) * 256 );
 strcpy( pBuf, outstream.str().c_str() );
 //p = pBuf;
 printf( pBuf );
}

Posted by gsi
: