在void CMyEditView::OnDraw(CDC* pDC)
{
RECT rect;
int a;
CRect rc;
// GetClientRect(&rect);
rect.bottom=100;
rect.left=10;
rect.right =400;
rect.top=10;
CEditDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
a=pDC->DrawText("this is a test string. this is a test string. this is a test string. this is a test string. ",&rect,DT_BOTTOM);
ReleaseDC(pDC); // TODO: add draw code for native data here
}
为什么不能输出多行文本?

解决方案 »

  1.   

    这样才能输出!!int ExtDrawText(CDC* pDC,LPCSTR lpszString, int nCount, LPRECT lpRect,UINT nFormat)
    {
    if(!(nFormat & DT_WORDBREAK))
    return pDC->DrawText(lpszString,nCount,lpRect,nFormat);

    CRect rect( lpRect->right,lpRect->bottom,lpRect->left, lpRect->top );
    rect.top    -= 5;
    rect.bottom += 5;
    rect.left   += 5;
    rect.right  -= 5;
    int width = rect.Width();
    char * temp = new char[2*strlen(lpszString)+1];
    strcpy(temp,lpszString);
    char* cur;          
    cur = temp;
    int j;
    CSize size;
    while(*cur != '\0')
        {
    j=1;
    do
    {
    if(cur[j-1] == '\r' || cur[j-1] == '\0') break;
    size = pDC->GetTextExtent(cur,j);
    if(size.cx > width) break;
    j++;
    }while(1);
    if(j == 1) break;
    j--;
    if(cur[j] == '\0') break;
    if(cur[j] != '\r' && !(cur[j] & 0x80))
            {
    memmove(&cur[j+1],&cur[j],strlen(&cur[j])+1);
    cur[j] = '\n';
            }   
    cur += j+1;
        }  
    int ret = pDC->DrawText(temp,nCount,&rect,nFormat);
    // int ret = pDC->ExtTextOut(rect.left,rect.top,ETO_CLIPPED,rect,temp,NULL);
    delete[] temp;
    return ret;
    }
      

  2.   

    a=pDC->DrawText("this is a test string.\n this is a test string. this \nis a test string. this is a test string. ",&rect,DT_BOTTOM);
    加上回车符
      

  3.   

    能不能随RECT的宽度自动换行呢?
      

  4.   

    auly403(深山里):
       你实验一下,一楼的程序可以自动根据字体,RECT的宽度实现换行的!!!!
      

  5.   


    a=pDC->DrawText("this is a test string. this is a test string. this is a test string. this is a test string. ",&rect,DT_WORDBREAK);
      

  6.   

    to chenhq(chenhq):
    试过,但它不能输出文字,能否把源代码发过来,再开贴给分你好吗?
    EMIAL: [email protected]