我有一个丰富的编辑控件,我想在其中添加格式化文本,但它不起作用:
const char* str="{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard\
This is some {\b bold} text.\par\
}";
LoadLibrary("riched32.dll");
HWND hEdit= CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS, str,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
| ES_READONLY, 0, 0, 100, 100,
hwnd, (HMENU) IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
我知道我可以使用PARAFORMAT
和CHARFORMAT
添加格式,并向控件发送消息,如下所示:
PARAFORMAT pf;
CHARFORMAT cf;
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_BOLD;
cf.dwEffects = CFE_BOLD;
SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
SendMessage( hEdit, EM_REPLACESEL, FALSE, (LPARAM) "bold ");
但是如何让第一个工作或者如果没有办法,是否有比第二个更简单的方法?提前谢谢。