日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CDC的DrawText

發(fā)布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CDC的DrawText 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

CDC::DrawText

語法

參數(shù)

返回值

例子:

多行文字的豎直居中?

獲取多行文本(超過width后自動換行)的高度

附錄


CDC::DrawText

調(diào)用該成員函數(shù)的格式在給定矩形的文本。??若要指定附加格式設(shè)置選項(xiàng),請使用 CDC::DrawTextEx。??

語法

復(fù)制

virtual int DrawText(LPCTSTR lpszString,int nCount,LPRECT lpRect,UINT nFormat ); int DrawText(const CString& str,LPRECT lpRect,UINT nFormat );

參數(shù)

  • lpszString
    指向要繪制的字符串。??如果 nCount 是–必須對停止點(diǎn)1,字符串。??

  • nCount
    在字符串指定字符數(shù)。??如果 nCount 為– 1,則 lpszString 假定為較長的指針到一個Null終止的字符串,并 DrawText 自動計(jì)算字符數(shù)。??

  • lpRect
    指向 RECT 包含矩形的結(jié)構(gòu)或 CRect 對象(以邏輯坐標(biāo))文本會進(jìn)行格式設(shè)置。

  • str
    包含要繪制的指定字符的 CString 對象。

  • nFormat
    指定將該文本的格式設(shè)置方法。??它可以是 uFormat 參數(shù)描述的值的任意組合。DrawText 在 Windows SDK。??(請按位組合使用或運(yùn)算符):??

備注

某些 uFormat 標(biāo)志組合可能會導(dǎo)致該傳遞的字符串進(jìn)行修改。??使用 DT_MODIFYSTRINGDT_END_ELLIPSISDT_PATH_ELLIPSIS 可導(dǎo)致該字符串被修改,導(dǎo)致斷言在 CString 重寫。??值 DT_CALCRECTDT_EXTERNALLEADINGDT_INTERNALDT_NOCLIPDT_NOPREFIX 不能與 DT_TABSTOP 值。??

返回值

文本的高度,如果函數(shù)運(yùn)行成功。

例子:

CString str = L"我是來自非洲的姑娘。心中向往神秘的東方,背起行囊尋找夢想,那是龍的故鄉(xiāng)。這里的人純樸善良, 淡淡微笑掛臉龐。";CRect temp(0, 0, rect.Width(), 0); // int h1 = pDC->DrawText(str, temp, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);//144 文本折行后的文本高度 // int h2 = pDC->DrawText(str, temp, DT_CALCRECT | DT_WORDBREAK);//144 // int h3 = pDC->DrawText(str, temp, DT_CALCRECT | DT_EDITCONTROL);//16 單行文本的高度 // int h4 = pDC->DrawText(str, temp, DT_CALCRECT);//16

多行文字的豎直居中?

//多行文字的豎直居中 // 思路:根據(jù)顯示中心,重新計(jì)算要求的顯示范圍 // 具體方法: // ====================================== // 把str內(nèi)容顯示到客戶區(qū)的中間,但是每行寬度限定為200,讓其自動換行 void CtestDialogDlg::test(CDC* pDC) {CFont ft;ft.CreatePointFont(120,L"楷體"); // 大小與實(shí)際大小相差10倍CFont* pOldFont = pDC->SelectObject(&ft);CRect clientRect;GetClientRect(clientRect); // 獲得客戶區(qū)范圍CRect rect;rect.left = rect.top = 10;rect.right = 200;//rect.bottom = clientRect.bottom; // 限定寬度rect.bottom = 200;pDC->SelectStockObject(NULL_BRUSH);pDC->Rectangle(rect);CString str = L"我是來自非洲的姑娘。心中向往神秘的東方,背起行囊尋找夢想,那是龍的故鄉(xiāng)。這里的人純樸善良, 淡淡微笑掛臉龐。";CRect temp(0, 0, rect.Width(), 0);int height = pDC->DrawText(str, temp, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL); // 獲得文本高度 144rect.DeflateRect(2, (rect.Height() - height) / 2); // 改變rectCPen p1(PS_DASH, 1, RGB(255, 0, 0));CPen* pOldPen = pDC->SelectObject(&p1);pDC->Rectangle(rect);pDC->SelectObject(pOldPen);pDC->SetBkMode(TRANSPARENT);//pDC->DrawText(str, rect, DT_CENTER | DT_EDITCONTROL | DT_WORDBREAK);pDC->DrawTextW(str, rect, DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK);pDC->SelectObject(pOldFont);}

正常使用是這樣的:

CRect rc(140, 20, 240, 100);rc.DeflateRect(4, 4);CString str = L"我是來自非洲的姑娘。心中向往神秘的東方,背起行囊尋找夢想,那是龍的故鄉(xiāng)。這里的人純樸善良, 淡淡微笑掛臉龐。";dc.DrawTextW(str, rc, DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK);

若rect的大小不能放下該字符串,則只顯示能顯示的部分。如圖

若rect能放的下,就顯示全了。故最好先計(jì)算一下height,構(gòu)造一個合適的rect,再DrawText。如下:

CRect rc(140, 20, 240, 100);CString str = L"我是來自非洲的姑娘。心中向往神秘的東方,背起行囊尋找夢想,那是龍的故鄉(xiāng)。這里的人純樸善良, 淡淡微笑掛臉龐。";int height = dc.DrawText(str, CRect(0,0,rc.Width(),0), DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);CRect rc2 = rc;rc2.bottom = rc2.top + height;dc.Rectangle(rc2);dc.DrawTextW(str, rc2, DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK);

?

獲取多行文本(超過width后自動換行)的高度

//通過width獲取多行文本(超過width后自動換行)的高度 int GetTextHeightByWidth(CDC* pDC, const CString& strText, int width) {CRect temp(0, 0, width, 0);int height = pDC->DrawText(strText, temp, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL); // 獲得文本高度 144return height; }

?

?

?


附錄

DrawText 中的參數(shù) nFormat 可以取一下的值

The method of formatting the text. This parameter can be one or more of the following values.

表 1ValueMeaning

DT_BOTTOM

Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value.

DT_CALCRECT

Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the largest word is wider than the rectangle, the width is expanded. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText modifies 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 in the rectangle.

DT_EDITCONTROL

Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.

DT_END_ELLIPSIS

For displayed text, if the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses.

The string is not modified unless the DT_MODIFYSTRING flag is specified.

Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS.

DT_EXPANDTABS

Expands tab characters. The default number of characters per tab is eight. The DT_WORD_ELLIPSIS, DT_PATH_ELLIPSIS, and DT_END_ELLIPSIS values cannot be used with the DT_EXPANDTABS value.

DT_EXTERNALLEADING

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

DT_HIDEPREFIX

Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other mnemonic-prefix characters are still processed.

Example:

input string: "A&bc&&d"

normal: "Abc&d"

DT_HIDEPREFIX: "Abc&d"

Compare with DT_NOPREFIX and DT_PREFIXONLY.

DT_INTERNAL

Uses the system font to calculate text metrics.

DT_LEFT

Aligns text to the left.

DT_MODIFYSTRING

Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified.

DT_NOCLIP

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

DT_NOFULLWIDTHCHARBREAK

Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings. For example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified.

DT_NOPREFIX

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

Example:

input string: "A&bc&&d"

normal: "Abc&d"

DT_NOPREFIX: "A&bc&&d"

Compare with DT_HIDEPREFIX and DT_PREFIXONLY.

DT_PATH_ELLIPSIS

For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.

The string is not modified unless the DT_MODIFYSTRING flag is specified.

Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS.

DT_PREFIXONLY

Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any other characters in the string. For example,

Example:

input string: "A&bc&&d"n

normal: "Abc&d"

DT_PREFIXONLY: " _ "

Compare with DT_HIDEPREFIX and DT_NOPREFIX.

DT_RIGHT

Aligns text to the right.

DT_RTLREADING

Layout in right-to-left reading order for bidirectional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right.

DT_SINGLELINE

Displays text on a single line only. Carriage returns and line feeds do not break the line.

DT_TABSTOP

Sets tab stops. Bits 15-8 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight. The DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value.

DT_TOP

Justifies the text to the top of the rectangle.

DT_VCENTER

Centers text vertically. This value is used only with the DT_SINGLELINE value.

DT_WORDBREAK

Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-line feed sequence also breaks the line.

If this is not specified, output is on one line.

DT_WORD_ELLIPSIS

Truncates any word that does not fit in the rectangle and adds ellipses.

Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS.

總結(jié)

以上是生活随笔為你收集整理的CDC的DrawText的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产一区二区激情 | 一级片久久 | 五级 黄 色 片 | 久久人人妻人人人人妻性色av | 美女伊人网 | 在线综合色 | 亚洲精品视频在线观看免费视频 | 日日干天天爽 | 黄色片在线免费看 | 精品亚洲aⅴ无码一区二区三区 | 午夜天堂视频 | 欧美色性视频 | 男人看的网站 | 性一交一乱一伧老太 | 日本三级久久 | 337p粉嫩大胆噜噜噜亚瑟影院 | 午夜一区二区三区免费 | 成人午夜免费毛片 | 久久91久久| 亚洲制服另类 | 在线免费观看亚洲 | 夜夜视频 | www操操操| 国产日韩精品一区二区 | 91视频专区 | 久久成人乱码欧美精品一区二区 | 日韩女优中文字幕 | 99热网站 | 久久久88| 成人av中文字幕 | 操操操操操操操操操操 | 国产欧美一区二区视频 | 色小说在线 | 国产美女视频 | av色噜噜 | www,jizz,com| 日本一区久久 | 无码人妻一区二区三区线 | 青青草国产 | 又色又爽又黄gif动态图 | 美女作爱网站 | 国产人与禽zoz0性伦 | 日韩少妇激情 | 国产精品久久久久久久久久 | 激情精品 | 欧美久久综合 | 日本xx视频| 国产一线二线在线观看 | 国产www视频| 国产主播自拍av | 日韩免费av一区二区 | 国产成人观看 | 另类天堂av | 嫦娥性艳史bd | 国产精品久久久久桃色tv | 欧美黄色录像 | 国产成人精品一区二区三区网站观看 | 丰满少妇毛片 | 国产又爽又黄视频 | 色94色欧美 | 免费裸体美女网站 | 国产福利在线观看 | 亚洲一区二区激情 | 五十路中出 | 婷婷伊人综合中文字幕 | 中文精品在线观看 | www.桃色av嫩草.com | 久久国产精品系列 | 日批网站在线观看 | 深夜国产在线 | 人人妻人人澡人人爽人人dvd | 性久久久久久久久久久久 | 仙踪林久久久久久久999 | 五月婷婷av | 伊人精品在线视频 | 欧美二区视频 | 国产精品电影一区 | 视频一区二区三区四区五区 | 亚洲免费专区 | av资源首页 | 福利毛片 | 精品国产乱码久久久久久久软件 | 国产人人插 | 欧洲精品一区二区 | 免费不卡视频 | 免费欧美一区 | 抖音视频在线观看 | 欧美日韩中文 | 天天躁日日躁aaaaxxxx | 色小姐av| 精品亚洲一区二区三区 | 国产福利不卡 | 欧美va亚洲va | 久久一 | 日本一区二区三区精品视频 | 伊人久色 | 久久亚洲AV无码 | 草草影院ccyycom | 97潮色 |