c++ - mfc - 富文本消息框

标签 c++ windows mfc richtext

我希望能够在消息框中显示格式化文本(如粗体文本、项目符号点、斜体等)。

我遇到了this wonderful article但似乎无法让它发挥作用。我正在同一链接上使用演示应用程序。

有人可以帮我吗?我尝试调试/理解该代码,但没有成功。

限制:(不是我的选择)

  • 必须与 Windows XP 兼容。
  • 我使用的是 Visual C++ 6。

它应该如何显示:

How it is supposed to display


实际显示方式:

enter image description here

最佳答案

只需使用 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/

相关文章:

c++ - 将 DLL 中的非导出函数声明为静态的原因

c++ - if/else 在什么阶段变得比 switch case 更好?可以?

c++ - 轮询后 SDL_Event.type 始终为空

mysql - 在 MySQL/8 for Windows 中禁用二进制日志记录

windows - Xbox 开发不在 Vista 或 7 上

c++ - 是否可以为具有可变参数的宏定义 c++ 包装函数?

c++ - 应用程序不能与 VS 2008 SP1 DLL 一起运行,以前的版本适用于 RTM 版本

c++ - 使用 CMake 构建 zLib

c++ - 如何让鼠标的位置连续离开对话框? (MFC)

C++/MFC 有没有办法在单击一个按钮的同时单击另一个按钮?