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 misspelled words.

I found one example where this is done, but it only works for a simple edit field, because it can just use the default edit font to perform calculations to draw squiggly lines. But this does not work for rich editing, as in the advanced editing control it is possible that different words may have different fonts. In this case, the example I found draws lines in the wrong places.

Please let me know if someone has already done this for CRichEditCtrl? (It should handle the text of any font / size that is present in the advanced edit control.)

Thanks Sachin

+3
source share
2 answers
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 your text will underline

+3
source

Use the message EM_SETCHARFORMAT :

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);
+1
source

Source: https://habr.com/ru/post/1789953/


All Articles