VC DrawText显示多行,包括设置行距。
2010-04-26 09:50
337 查看
int DrawMultLineText(HDC hDC , int nXStart , int nYStart , int nWidth , int nRowHeight , LPCTSTR pBuff) { TEXTMETRIC tm; LPCTSTR pChar; if(!GetTextMetrics(hDC , &tm)) return 0; CPoint posStart , posCurr; int nRowCount = 0; pChar = pBuff; posStart.SetPoint(nXStart , nYStart); for(; *pChar ; pChar++) { if(*pChar == '\t') { MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmAveCharWidth , 4); } else { if(*pChar == '\r') { posCurr.y += nRowHeight; posCurr.x = posStart.x; if( *(pChar + 1) == '\n') pChar++; } else if(*pChar == '\n') { posCurr.y += nRowHeight; posCurr.x = posStart.x; } else if( IsChineseChar(pChar)) { TextOut(hDC , posCurr.x , posCurr.y ,pChar , 2); MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmMaxCharWidth , 1) ; pChar ++; } else { TextOut(hDC , posCurr.x , posCurr.y ,pChar , 1); MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmAveCharWidth , 1); } } } return (posCurr.y + posStart.y) / nRowHeight; } void MovePos(const POINT &posStart , POINT &posCurr , int nColWidth , int nRowHeight , int nCharWidth , int nCount) { int i; if(nColWidth < nCharWidth) return; if(posStart.x > posCurr.x) posCurr.x = posStart.x; if(posStart.y > posCurr.y) posCurr.y = posStart.y; for(i = 0 ; i < nCount ; i++) { posCurr.x += nCharWidth; if(posCurr.x > nColWidth) { posCurr.x = posStart.x; posCurr.y += nRowHeight; } } } BOOL IsChineseChar(LPCTSTR str) { return *str < 0 && (*(str + 1)) < 0; }
相关文章推荐
- android中textview设置为多行文本时,如何让文字从最顶开始显示
- android中textview设置为多行文本时,如何让文字从最顶开始显示
- Android进阶之路 - TextView与EditText单行显示,多行显示,超过限制使用省略号,行距,字距,键盘隐藏与显示
- 设置TextView显示的文字可以复制
- Android textview显示多行
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- textview设置字体的行距和字间距
- IE7 部分标签设置text-indent:-9999px后不在相应位置显示的处理
- TextView设置一行最多显示5个字是什么属性
- (七十三)Android 设置EditText光标颜色及粗细 和设定EditText的光标为显示/隐藏
- textview设置超出11个长度时显示省略号
- js 通过html()及text()方法获取并设置p标签的显示值
- Android ScrollView 中 TextView 多行显示问题
- android textview 多行之后显示省略号
- Android开发中如何给EditText设置多行效果
- TextView最多设置多少行,然后多出来打点显示(涉及的一些参数)
- 两种方法,针对EditText密码的显示和隐藏(包括激将光标移动到文本末尾)
- 当EditText是多行文本时, 光标如何设置在从左上角
- js使用html()或text()方法获取设置p标签的显示的值
- struts2 一行 显示 多个 <s:textfield 的问题(struts2 多行多列显示 struts2的主题设置)