void CT2Dlg::OnButton1() 
{
EchoMsg("aa");
EchoMsg("aa%d",10);
EchoMsg("aa%o",250);
EchoMsg("aa%c",31);
EchoMsg("aa%7d%2u",111,666);
}
void CT2Dlg::EchoMsg(LPCTSTR lpszFormat,...)
{ //显示一行信息.如果信息超过一定数量,删除前面2行
CString oldmsg,newmsg;
va_list arglist; 
va_start(arglist,lpszFormat);  newmsg.Format(lpszFormat,arglist);
m_edit.GetWindowText(oldmsg);
int oldlen=oldmsg.GetLength();
int tobeRep=0;
if(oldlen>5120)
{
tobeRep=oldmsg.Find("\r\n",oldmsg.Find("\r\n")+2)+2;
m_edit.SetSel(0,tobeRep);   
        m_edit.ReplaceSel("");
}
m_edit.SetSel(oldlen-tobeRep,oldlen-tobeRep);
m_edit.ReplaceSel(newmsg+"\r\n"); }
界面上一个button,一个Edit
运行结果是
aa
aa1242636
aa4573014
aa
aa12426321242720

解决方案 »

  1.   

    就是调用EchoMsg函数回显信息.
    作用类似printf()
    我函数只是增加了内容太多时删除头两行,这个不是问题的重点.
    重点是
        printf("aa");
        printf("aa%d",10);
        printf("aa%o",250);
        printf("aa%c",31);
        printf("aa%7d%2u",111,666); 
    不会得到
    aa 
    aa1242636 
    aa4573014 
    aa 
    aa12426321242720
      

  2.   

    真是言简意赅!感谢cnzdgs无数次解决小弟的问题.