I want to implement basic spell checking in a Notepad clone project I'm doing. I want to underline misspelled words with a squiggly like like Word does. I think I need to use GDI and draw on the text field, but I'm not sure how to draw on controls. Thanks
Actually, I'm not sure about the method which you're using to render text in your window and I think you need to concretize it.
If everything is done using winapi/gdi (generally speaking, this would be TextOut
ing the current text block, that fits the window considering wrapping, etc...), you should add another routine, that would handle misspelled words rendering.
Again, this also depends on your way to save current text and it's parameters, but the idea is to implement some sort of function like RenderMisspelledWord(...)
, which would take your generic text-handling class or some kind of renderer class or even (X, Y, Length)
as params. This function would be called from a more general Render
method, which would be called from WM_PAINT
handler.
What it would do also depends on your notepad architecture, but, for example, in last case that would require drawing * /\ /\ /\ * parts of your underlining using GDI (line) routines.
Generally speaking, every other case (with handling classes) would lead to the following action too, but with higher level of abstraction.
If you're basing your editor on an edit control (as Notepad does), then I think it's going to be difficult. By subclassing the edit control window, you could probably augment its WM_PAINT
handling. But the problem is the control doesn't expose a way for you to find out exactly where a word appears within the control. Thus you won't know where to draw the squiggle.
You might be able to use a Rich Edit control (as WordPad does) and tweak the styling of the misspelled words. I've never used Rich Edit, so I can't help with the details.