单词下的波浪线 (Win32)
我想在我正在做的记事本克隆项目中实现基本的拼写检查。我想像 Word 一样用波浪线在拼写错误的单词下划线。我想我需要使用 GDI 并在文本字段上绘图,但我不确定如何在控件上绘图。 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的编辑器基于编辑控件(如记事本),那么我认为这会很困难。通过子类化编辑控制窗口,您可以增强其
WM_PAINT
处理。但问题是该控件没有提供一种方法让您准确地找出单词在控件中出现的位置。因此你不知道在哪里画曲线。您也许可以使用 Rich Edit 控件(如写字板那样)并调整拼写错误的单词的样式。我从未使用过 Rich Edit,所以我无法帮助您了解详细信息。
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.
实际上,我不确定您用来在窗口中渲染文本的方法,我认为您需要将其具体化。
如果一切都是使用 winapi/gdi 完成的(一般来说,这将是
TextOut
ing 当前文本块,考虑到换行等适合窗口),您应该添加另一个例程,这将处理拼写错误的单词渲染。同样,这也取决于您保存当前文本及其参数的方式,但其想法是实现某种函数,例如 RenderMisspelledWord(...),它将采用您的通用文本-处理类或某种渲染器类甚至
(X, Y, Length)
作为参数。该函数将从更通用的 Render 方法中调用,该方法将从 WM_PAINT 处理程序中调用。它的作用还取决于您的记事本体系结构,但是,例如,在最后一种情况下,需要使用 GDI(行)例程绘制下划线的 * /\ /\ /\ * 部分。
一般来说,其他所有情况(带有处理类)也会导致以下操作,但具有更高的抽象级别。
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 generalRender
method, which would be called fromWM_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.