开发者

Squigglly line under a word (Win32)

开发者 https://www.devze.com 2022-12-27 19:39 出处:网络
I want to implement basic spell checking in a Notepad clon开发者_如何学Ce 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 dr

I want to implement basic spell checking in a Notepad clon开发者_如何学Ce 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


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.


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 TextOuting 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.

0

精彩评论

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

关注公众号