DrawText DT_CALCRECT with DT_WORDBREAK

huangapple go评论43阅读模式
英文:

DrawText DT_CALCRECT with DT_WORDBREAK

问题

我想获取打印文本的尺寸,以便在文本后面绘制位图。当我使用类似以下的内容时:

CRect rc2={ 0, 0, 0, 0 };
dc.DrawText(txt, &rc2, DT_CALCRECT);

一切都正常。但当我有很长的文本行,并想使用:

dc.DrawText(txt, &rc2, DT_CALCRECT|DT_WORDBREAK);

rc2 返回 0,0,0,0。我应该怎么办来解决这个问题?

英文:

I want to get dimensions, of printed text, to draw a bitmap after the text. When I use something like:

CRect rc2={ 0, 0, 0, 0 };
dc.DrawText(txt, &rc2, DT_CALCRECT); 

everything is ok. But when I have long text lines, and want to use

dc.DrawText(txt, &rc2, DT_CALCRECT|DT_WORDBREAK); 

rc2 returns 0,0,0,0. What can I do to fix this?

答案1

得分: 3

The right margin has to be specified, and the problem solved.

int rightmarg = PrintDC.GetDeviceCaps(HORZRES);
r.right = rightmarg;
DrawText(dc, txt, txt.GetLength(), &r, DT_CALCRECT|DT_WORDBREAK|DT_WORD_ELLIPSIS|DT_NOPREFIX);
英文:

The right margin has to be specified, and the problem solved.

int rightmarg=PrintDC.GetDeviceCaps(HORZRES);
r.right = rightmarg;
DrawText(dc, txt, txt.GetLength(), &r, DT_CALCRECT|DT_WORDBREAK|DT_WORD_ELLIPSIS|DT_NOPREFIX);

huangapple
  • 本文由 发表于 2023年3月31日 22:24:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定