如何实现整词换行? 顶者有分

liul17 2007-08-02 02:07:48
我通过GDI+实现了一个文本显示的东西,因为有一些特殊需求所以必须自己写,但不能整词的换行,整词换行就是像Word一样,当一行显示不下时,遇到是一个字时直接换行,当遇一个词时,将整个词换到下一行.
请问该怎么实现?

我知道词的规则,我也试过自己控制换行(计算 x,y值一个词一个词的打印,判断窗体的width,当超过宽度时换行,但运行效率太低)
求高效些的方法!!

大家帮忙想想办法!!
...全文
226 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
冰霜icefrost 2007-08-03
  • 打赏
  • 举报
回复
DrawText中有一个参数 ,DT_WORDBREAK 看看对你有没有用.
flypig917 2007-08-03
  • 打赏
  • 举报
回复
这个分词主要在CResult类的FileProcessing函数里进行的,你要是还是不太明白可以写信给我,我的邮箱是lujing18@yahoo.com.cn。
flypig917 2007-08-03
  • 打赏
  • 举报
回复
那你就得使用中科院计分词的方法这是网址:
www.nlp.org.cn;mtgroup.ict.ac.cn
luohongming 2007-08-03
  • 打赏
  • 举报
回复
mark
taianmonkey 2007-08-03
  • 打赏
  • 举报
回复
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.
smallfishff 2007-08-03
  • 打赏
  • 举报
回复
???理論上檢測空格不就可以了么? 把左邊最近空格之後的所有單詞全部轉入下一行?
nkeverstar 2007-08-02
  • 打赏
  • 举报
回复
up
pueler 2007-08-02
  • 打赏
  • 举报
回复
up
lgstudyvc 2007-08-02
  • 打赏
  • 举报
回复
一个单词写完时如果他的长度大于你该行剩下的长度就把他写在下一行的开始。

自己计算,几个变量就可以搞好吧
「已注销」 2007-08-02
  • 打赏
  • 举报
回复
这个问题可以解决的,用DRAWTEXT的一个参数,要新的SDK支持,好像是DT_NOFULLWIDTHCHARBREAK还是什么的,我也忘了,晚上回去找找
i_love_pc 2007-08-02
  • 打赏
  • 举报
回复
顶!!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧