英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论