开发者

How to display Red Squiggly Lines in CRichEditCtrl in MFC

I am working on implementing spellchecker in an MFC application. What I want to do is display red lines under incorrectly spelled words.

I found one example where it is done but it works only for a simple edit box because it can simply use the edit controls default font for doing calculations to draw the squiggly lines. But it does not work for a rich edit control as in rich edit control it is possible that different words can have different fonts. In this case the example I found draws lines at incorrect places.

Please let me know if someone has already done this for CRichEditCtrl? (it must handle text of any font/size that i开发者_StackOverflow社区s present in the rich edit control.)

Thanks, Sachin


CHARFORMAT2 format;
SecureZeroMemory(&format, sizeof(CHARFORMAT2));
format.cbSize = sizeof(CHARFORMAT2);
format.dwMask = CFM_UNDERLINE|CFM_UNDERLINETYPE;
format.dwEffects = CFE_UNDERLINE;
format.bUnderlineType = CFU_UNDERLINEWAVE | 0x50;
SendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);

I hope this will get the underline in your text


Use the EM_SETCHARFORMAT message:

CHARFORMAT2 format;
SecureZeroMemory(&format, sizeof(CHARFORMAT2));
format.cbSize = sizeof(CHARFORMAT2);
format.dwMask = CFM_UNDERLINE|CFM_UNDERLINETYPE;
format.dwEffects = CFE_UNDERLINE;
format.bUnderlineType = CFU_UNDERLINE
window->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
window->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜