我希望能够在消息框中显示格式化文本(如粗体文本、项目符号点、斜体等)。
我遇到了this wonderful article但似乎无法让它发挥作用。我正在同一链接上使用演示应用程序。
有人可以帮我吗?我尝试调试/理解该代码,但没有成功。
限制:(不是我的选择)
- 必须与 Windows XP 兼容。
- 我使用的是 Visual C++ 6。
它应该如何显示:
实际显示方式:
最佳答案
只需使用 RichEdit2 控件创建一个对话框弓...
在 InitInstance 中,添加以下调用:
// Init RichEdit Library
AfxInitRichEdit2();
在对话框中,为 RichEdit 控件创建一个变量并将其更新为:
// Turn Word Wrap on (based on window width)
m_RichEditMsg.SetTargetDevice( NULL, 0);
// Set Base Text
strText = "{\\rtf1\\ansi\\fs20 ";
strText += "{\\colortbl;\\red0\\green0\\blue0;\\red0\\green0\\blue255;\\red0\\green255\\blue255;\\red0\\green255\\blue0;\\red255\\green0\\blue0;}";
strText += "{\\f1\\cb1\\cf2\\b Main Title} \\par\\par \\fs18 Other text to add {\\b In Bold} no more in bolb ... \\par";
str.Format( "\\par Id: {\\b %s}", m_strProgId);
strText += str;
strText+= "\\par \\par {\\f1 \\b Please Confirm ...} \\par}";
// Update Controls
m_RichEditMsg.SetWindowText( strText);
只需构建您自己的消息,即可获得粗体、颜色……
关于c++ - mfc - 富文本消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402671/