Display text in a MFC application

2019-07-10 02:42发布

I need to display text in an MFC application. I have a sample text like "Display text in mfc application". Let's assume the client window in which I intend to draw this text is so small(horizontally) that in one line the only text that can fit is "Display text in". The words "mfc application" are not displayed. My question is, how do I ensure that these words are displayed in the next line, instead of just being clipped off?I'm using the drawtext function to display the text.

Thanks.

标签: mfc drawtext
2条回答
时光不老,我们不散
2楼-- · 2019-07-10 02:46

I had also the problem you reported. And solved it as I explained in https://stackoverflow.com/a/29241196/383779

You need first a call to DrawText with the DT_CALCRECT flag to know what rectangle to pass to the DrawText that really makes the work.

It is strange but ... it is the way it is. MFC ... you know.

查看更多
Viruses.
3楼-- · 2019-07-10 02:52

By default, DrawText API behaves exactly as you need, unless the DT_SINGLELINE format is specified. Just provide correct lpRect parameter.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498%28v=vs.85%29.aspx

MFC CDC::DrawText method has the same behavior.

Use GetClientRect function to get a window rectangle, and pass this rectangle to DrawText method.

查看更多
登录 后发表回答