导航
  • 主页
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • VC/MFC界面
  • VC/MFC 进程
  • VC/MFC 数据库
  • VC++技术资源

DrawText函数的参数

zhigangsun 2002-12-16 11:45:47
帮忙解释一下DrawText函数的参数意义,我没装(msdn)
...全文
458 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
howtotell 2002-12-16
CRect rcCalcText(0,0,0,0);
pDC->DrawText(strTmp, rcCalcText, DT_CALCRECT);

pDC->DrawText( strTmp, rcCalcText, DT_WORDBREAK | DT_EXPANDTABS);
回复
CRect r(0,3,100,200);
DraeText("give me ...",&r,DT_LEFT);
回复
1,virtual int DrawText(LPCTSTR lpszString,int nCount,
LPRECT lpRect,UINT nFormat);
2,int DraeText(const CString &str,
LPRECT lpRect,UINT nFormat);
lpszString 要显示的字符指针
lpRect 区域
nFormat:
DT—BUTTOM
DT—TOP
。。。。。。
DT—CALCRECT并不绘出,只是调整右下角。
DT—NOCLIP超出范围不切除
DT—WORDBREAK超出范围自动换行
回复
zhigangsun 2002-12-16
那怎样为lpRect赋值呀
回复
qhgary 2002-12-16
up
回复
sans 2002-12-16
CDC::DrawText
virtual int DrawText( LPCTSTR lpszString, int nCount, LPRECT lpRect, UINT nFormat );

int DrawText( const CString& str, LPRECT lpRect, UINT nFormat );

Return Value

The height of the text if the function is successful.

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 following values (combine using the bitwise OR operator):

DT_BOTTOM Specifies bottom-justified text. This value must be combined with DT_SINGLELINE.

DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle pointed to by lpRect and extend the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text, but does not draw the text.

DT_CENTER Centers text horizontally.

DT_EXPANDTABS Expands tab characters. The default number of characters per tab is eight.

DT_EXTERNALLEADING Includes the font's external leading in the line height. Normally, external leading is not included in the height of a line of text.

DT_LEFT Aligns text flush-left.

DT_NOCLIP Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.

DT_NOPREFIX Turns off processing of prefix characters. Normally, DrawText interprets the ampersand (&) mnemonic-prefix character as a directive to underscore the character that follows, and the two-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. By specifying DT_NOPREFIX, this processing is turned off.

DT_RIGHT Aligns text flush-right.

DT_SINGLELINE Specifies single line only. Carriage returns and linefeeds do not break the line.

DT_TABSTOP Sets tab stops. The high-order byte of nFormat is the number of characters for each tab. The default number of characters per tab is eight.

DT_TOP Specifies top-justified text (single line only).

DT_VCENTER Specifies vertically centered text (single line only).

DT_WORDBREAK Specifies word-breaking. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by lpRect. A carriage return–linefeed sequence will also break the line.

Note The values DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX cannot be used with the DT_TABSTOP value.

Remarks

Call this member function to format text in the given rectangle. 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).

回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……