把\n换成
\r\n 还是 \n\r 我忘了
你试试!

解决方案 »

  1.   

    TextOut不能换行。DrawText能换行,以为他支持转义字符,但会把&后的字符下滑线等。怎么感到很恶心!?
      

  2.   

    DrawText的用法和TextOut一样吗?
      

  3.   

    TextOut不行,要用DrawText,可以打印一个区域。
      

  4.   

    int DrawText( const CString& str, LPRECT lpRect, UINT nFormat );怎样得到那些参数?
    程序在OnPaint()中。
      

  5.   

    RECT rect;
    GetClientRect(&rect);
    DrawText(pDC->m_hDC,pbuf,_tcslen(pbuf),&rect,DT_INTERNAL);
      

  6.   

    void xxxx::OnPaint()
    {
        CPaintDC dc(this);
        CString str("想写什么就写什么,\r\n这不是很简单的事么?");
        CRect rc;
        GetClientRect(rc);
        dc.DrawText(str,rc,DT_LEFT);
    }
      

  7.   

    kimryo(轻*轻*前*轻*重):Where is the "DT_INTERNAL" ?
      

  8.   

    怎样指定rect的某一行呢?
    加分!
      

  9.   

    你不会用多个TextOut或用DrawText
    vc编程中文本输出的座标是要自己定的
    TextOut和DrawText参数中都有表明座标值的参数
      

  10.   

    DrawText中有坐标参数吗?
    没看见啊?
      

  11.   

    LPRECT lpRect是矩形结构,它的成员包括矩形坐标,你可为矩形对象的成员赋值再调用DrawText
      

  12.   

    DrawTextEx(hdc, lpstring, -1, &rc, DT_TOP | DT_LEFT, NULL);就可以了,rc就是绘制区域
      

  13.   

    rect中的前面几行已经有数据了。
    想把新的数据写到后几行。
      

  14.   

    前面几行已经用TextOut写过了。
    下面接下来几行,要用DrawText来写。
      

  15.   

    请问怎样用DrawText下移文本?
      

  16.   

    用 _T("...")的形式不可以吗?
    为什么要那么复杂呢?
    其实还可以用 cout 的,你看过essential c++ 了吗?
    介意看看就知道怎么做了
      

  17.   

    _T("...")只是一个宏,为了方便程序转换成UNICODE而已
      

  18.   

    BOOL CMovieStatic::OnEraseBkgnd(CDC* pDC) 
    {
    CRect rect;
    CRgn rgn;
    CFont* font;
    if(m_UseSysFont)
    font=GetFont();
    else
    font=&m_Font; GetClientRect(&rect);
    rgn.CreateRectRgnIndirect(&rect);
    pDC->SelectClipRgn(&rgn);

    CString text;
    CMemDC memDC(pDC);
    CDC* pdc=&memDC; pdc->FillRect(&rect,&CBrush(m_BkColor));
    pdc->SetBkMode(TRANSPARENT);
    pdc->SetTextColor(m_FontColor); CFont* OldFont=pdc->SelectObject(font);
    if(!m_DisplayInfo){
    GetWindowText(text);

    pdc->TextOut(m_XPos,m_YPos,text);
    }else{//display MP3 info.
    UINT xpos,ypos;

    long step=GetFontHeight(font);

    //draw selected MP3 information.
    xpos=ypos=1;
    pdc->TextOut(xpos,ypos,"歌手: "+m_Singer);
    ypos+=step;
    pdc->TextOut(xpos,++ypos,"歌名: "+m_Song);
    ypos+=step;
    pdc->TextOut(xpos,++ypos,"专辑: "+m_Album);
    ypos+=step;
    pdc->TextOut(xpos,++ypos,"注释: "+m_Comment);
    ypos+=step;
    pdc->TextOut(xpos,++ypos,"日期: "+m_Year); m_TextArea.top=4;
    m_TextArea.left=4;
    m_TextArea.bottom=ypos+step;
    m_TextArea.right=rect.Width()-GetFontHeight(font)*4; //draw state text and icon.
    CString state="正在播放:";
    CBrush brush;
    POINT point;
    CRgn frgn;
    ypos+=rect.Height()/2-ypos; POINT vertex[4]={{xpos,ypos},{xpos+step,ypos+step/2},{xpos,ypos+step},{0,0}};
    m_PlayInfo.PlayIconRect.top=ypos;
    m_PlayInfo.PlayIconRect.left=xpos;
    m_PlayInfo.PlayIconRect.right=xpos+step;
    m_PlayInfo.PlayIconRect.bottom=ypos+step;
    if(!m_PlayInfo.PlayState){
    brush.CreateSolidBrush(RGB(255,0,0));
    frgn.CreateRectRgn(xpos,ypos,xpos+step,ypos+step);
    pdc->FillRgn(&frgn,&brush);
    state="停止.";
    }else if(m_PlayInfo.PlayState==PSTATE_PAUSED){
    state="暂停.";
    brush.CreateSolidBrush(RGB(0,255,255));
    frgn.CreateRectRgn(xpos,ypos,xpos+step/2-1,ypos+step);
    if((m_PlayInfo.XPos/10)%2==0){
    pdc->FillRgn(&frgn,&brush);
    frgn.DeleteObject();
    frgn.CreateRectRgn(xpos+step/2+1,ypos,xpos+step,ypos+GetFontHeight(font));
    pdc->FillRgn(&frgn,&brush);
    }
    }else{
    brush.CreateSolidBrush(RGB(0,255,0));
    frgn.CreatePolygonRgn(vertex,3,WINDING);
    pdc->FillRgn(&frgn,&brush);
    }
    brush.DeleteObject();
    frgn.DeleteObject();
    xpos+=step+2;
    pdc->TextOut(xpos,ypos,state); //draw playing MP3 information.
    if(!m_PlayInfo.PlayState)
    goto out;
    //do not display blanks.
    m_PlayInfo.Singer.TrimLeft();
    m_PlayInfo.Singer.TrimRight();
    m_PlayInfo.Song.TrimRight();
    m_PlayInfo.Song.TrimLeft();
    if(m_PlayInfo.Singer.IsEmpty())
    m_PlayInfo.Singer="未知歌手";
    if(m_PlayInfo.Song.IsEmpty())
    m_PlayInfo.Song="未知歌曲";
    CString disp="**"+m_PlayInfo.Singer+" - "+m_PlayInfo.Song+"** <"+m_PlayInfo.Time+"> ";
    ypos+=step+5;
    pdc->TextOut(m_PlayInfo.XPos,ypos,disp);
    if(rect.Width()<=GetFontWidth(font,disp)){
    m_PlayInfo.Offset=GetFontWidth(font,disp)-rect.Width()+1;
    if(m_PlayInfo.Offset>=rect.Width())
    m_PlayInfo.Offset/=2;
    }
    if(m_PlayInfo.XPos>(rect.Width()-GetFontWidth(font,disp))+m_PlayInfo.Offset)
    pdc->TextOut((m_PlayInfo.XPos+GetFontWidth(font,disp)-rect.Width()-m_PlayInfo.Offset)-GetFontWidth(font,disp),ypos,disp); //draw progress line.
    ypos+=step+step/2;
    CPen pen;
    CPen* OldPen;
    vertex[0].x=3;vertex[0].y=ypos+2;
    vertex[1].x=rect.Width()-3;vertex[1].y=vertex[0].y;
    m_PlayInfo.ProgBarRect.top=ypos-3;
    m_PlayInfo.ProgBarRect.left=vertex[0].x-2;
    m_PlayInfo.ProgBarRect.bottom=vertex[0].y+2+5;
    m_PlayInfo.ProgBarRect.right=vertex[1].x+2;
    if(m_PlayInfo.IsMovingCube){
    pen.CreatePen(PS_SOLID,1,RGB(100,245,120));
    OldPen=pdc->SelectObject(&pen);
    pdc->FillRect(&m_PlayInfo.ProgBarRect,&CBrush(RGB(85,155,57)));
    pdc->DrawFocusRect(&m_PlayInfo.ProgBarRect);
    pdc->SelectObject(OldPen);
    pen.DeleteObject();
    }
    pen.CreatePen(PS_SOLID,1,RGB(115,10,25));
    OldPen=pdc->SelectObject(&pen);
    pdc->MoveTo(vertex[0]);
    pdc->LineTo(vertex[1]);
    pdc->SelectObject(OldPen);
    pen.DeleteObject();
    pen.CreatePen(PS_SOLID,1,RGB(151,50,50));
    OldPen=pdc->SelectObject(&pen);
    vertex[0].y=++vertex[1].y;
    pdc->MoveTo(vertex[0]);
    pdc->LineTo(vertex[1]);
    pdc->SelectObject(OldPen);
    pen.DeleteObject();

    //draw cube.
    point.y=ypos;
    if(!m_PlayInfo.IsMovingCube){
    m_PlayInfo.CubeRect.top=point.y;
    m_PlayInfo.CubeRect.left=GetRelativePos()+2;
    m_PlayInfo.CubeRect.bottom=point.y+6;
    m_PlayInfo.CubeRect.right=GetRelativePos()+12+2;//Cube length is 12 pixels
    }
    frgn.CreateRectRgn(m_PlayInfo.CubeRect.left,m_PlayInfo.CubeRect.top,m_PlayInfo.CubeRect.right,m_PlayInfo.CubeRect.bottom);
    pdc->FillRgn(&frgn,&CBrush(m_PlayInfo.CubeColor));
    frgn.DeleteObject();

    //draw current time.
    GetDisplayTime();
    ypos+=step;
    disp="[ "+m_PlayInfo.C_Time+" ]";
    pdc->TextOut(rect.Width()/2-GetFontWidth(font,disp)/2,ypos,disp);
    m_PlayInfo.TimeRect.top=ypos;
    m_PlayInfo.TimeRect.left=rect.Width()/2-GetFontWidth(font,disp)/2;
    m_PlayInfo.TimeRect.bottom=ypos+step;
    m_PlayInfo.TimeRect.right=m_PlayInfo.TimeRect.left+GetFontWidth(font,disp); //draw mousemove predict time.
    if(!m_PlayInfo.PredictTime.IsEmpty()){
    GetCursorPos(&point);
    ScreenToClient(&point);
    if(!IsPointInRect(&rect,&CPoint(point)))
    pdc->SetTextColor(RGB(17,179,21));
    pdc->TextOut(1,ypos,"跳转到:"+m_PlayInfo.PredictTime);
    pdc->SetTextColor(m_FontColor);
    }

    //draw lyric if any.
    ypos=rect.Height()-step-2;
    CString ln1,ln2;
    GetDispLyric(m_PlayInfo.Lyric,&ln1,&ln2);
    int txtlen=GetFontWidth(font,m_PlayInfo.Lyric);
    int pos=txtlen-rect.Width();
    if(pos>0)
    ypos-=step;
    pdc->TextOut(1,ypos,ln1);
    if(pos>0)
    ypos+=step;
    //right align the second line lyric.
    txtlen=GetFontWidth(font,ln2);
    pdc->TextOut(rect.Width()-txtlen-2,ypos,ln2);
    }
    out:
    pdc->SelectObject(OldFont);
    rgn.DeleteObject();

    return CStatic::OnEraseBkgnd(pDC);
    }慢慢啃吧。
      

  19.   


    long CMovieStatic::GetFontHeight(CFont *font,CString str)
    {
    CDC* dc=GetDC();
    CFont* pOldFont;
    CSize size(0,0);

    if(font){
    pOldFont=dc->SelectObject(font);
    TEXTMETRIC ti;
    dc->GetTextMetrics(&ti);
    size=dc->GetTextExtent(str);
    dc->SelectObject(pOldFont);
    }
        ReleaseDC(dc);
    return (LONG)size.cy;
    }
      

  20.   

    增加drawtext使用的Y参数就可以
      

  21.   

    对啊!为什么不用DrawText呢?
    (DrawText是不是API啊?我也不是很清楚的)
      

  22.   

    TextOut 完全可以分行显示,我以前做过
    分行在字符串中是0ah 0dh 把这个添到你要分行的位置在显示这个字符串就行了
      

  23.   

    我用VC的WIN32模式做过一个自动滚屏文本阅读器,也遇到这个问题。
    好像是不可以的,“\n”会被显示成空格。你可以想个别的办法(我就是这样做的)。
      

  24.   

    CDC::DrawText(string,Rect,DT_WORDBREAK);
      

  25.   

    这个问题复杂吗?自己些一段代码,计算字符串中的/r/n的个数,然后
    根据当前字体的大小,计算出下一行的起始位置.我想DrawText里面肯
    定也是这样实现.为什么不花半个小时来解决这个问题?非常简单,我以
    前就写过这样的代码,将textbox中的multiline的文本在一个区域中
    显示出来,完全是自己写的代码,连DrawText都没有用.TextOut之会将
    /r/n之类的字符显示成奇怪的字符,根本不能够使用.
      

  26.   

    将基类由CView改为CRichView即可