Display text in a MFC application

若如初见. 提交于 2020-01-04 07:28:49

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11304947/display-text-in-a-mfc-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!