0

我正在尝试实现类似于域突出显示的东西。我希望富编辑框中的部分文本具有不同的颜色,就像我们在 IE 的域突出显示功能中一样。

问题:我知道我们必须先使用EM_EXSETSEL来选择所需的文本,然后再应用EM_SETCHARFORMAT

EM_EXSETSEL执行所需的操作并正确选择所需的文本。但是,当我执行EM_SETCHARFORMAT时,所选文本不会发生任何变化。

窗口是使用 RICHEDIT_CLASS 创建的。

任何帮助,将不胜感激。

4

1 回答 1

0

How about something like this (to set bold, red text on the current selection):

   // Set up the CHARFORMAT structure
   CHARFORMAT cfm;
   cfm.cbSize = sizeof(cfm);    // Don't forget this!

   // Get char format
   ::SendMessage(hWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);

   // Set the new effects
   cfm.dwEffects   = CFE_BOLD;
   cfm.crTextColor = RGB(255,0,0);
   cfm.dwMask      = CFM_BOLD | CFM_COLOR;

   // Set the new format
   ::SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);

where hWnd is the window handle of the Rich Edit control.

If not... then post some code, so we can see where you might be going wrong...

于 2012-11-21T15:43:36.923 回答