str很长! 用\r\n 无法实现, 如何实现?

解决方案 »

  1.   

    用TEXTOUT的话,换行时必须计算下一行的列坐标值,具体做法是列数*字体高度就可以TEXTOUT不支持\r\n换行。
    你可以派生自CEditView类,它是支持\r\n换行的。
      

  2.   

    用DrawText可以换行What is DrawText? MSDN:int DrawText(
       const CString& str,
       LPRECT lpRect,
       UINT nFormat 
    );
    Parameters
    lpszString 
    Points to the string to be drawn. If nCount is –1, the string must be null-terminated. 
    nCount 
    Specifies the number of chars in the string. If nCount is –1, then lpszString is assumed to be a long pointer to a null-terminated string and DrawText computes the character count automatically. 
    lpRect 
    Points to a RECT structure or CRect object that contains the rectangle (in logical coordinates) in which the text is to be formatted. 
    str 
    A CString object that contains the specified characters to be drawn. 
    nFormat 
    Specifies the method of formatting the text. It can be any combination of the values described for the uFormat parameter in DrawText in the Platform SDK. (combine using the bitwise OR operator): 
    Note   Some uFormat flag combinations can cause the passed string to be modified. Using DT_MODIFYSTRING with either DT_END_ELLIPSIS or DT_PATH_ELLIPSIS may cause the string to be modified, causing an assertion in the CString override. The values DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX cannot be used with the DT_TABSTOP value.
    Return Value
    The height of the text if the function is successful.Res
    It formats text by expanding tabs into appropriate spaces, aligning text to the left, right, or center of the given rectangle, and breaking text into lines that fit within the given rectangle. The type of formatting is specified by nFormat. This member function uses the device context's selected font, text color, and background color to draw the text. Unless the DT_NOCLIP format is used, DrawText clips the text so that the text does not appear outside the given rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is given. If the selected font is too large for the specified rectangle, the DrawText member function does not attempt to substitute a smaller font.If the DT_CALCRECT flag is specified, the rectangle specified by lpRect will be updated to reflect the width and height needed to draw the text.If the TA_UPDATECP text-alignment flag has been set (see CDC::SetTextAlign), DrawText will display text starting at the current position, rather than at the left of the given rectangle. DrawText will not wrap text when the TA_UPDATECP flag has been set (that is, the DT_WORDBREAK flag will have no effect).The text color may be set by CDC::SetTextColor