单词下的波浪线 (Win32)

发布于 2024-08-30 05:57:14 字数 100 浏览 3 评论 0原文

我想在我正在做的记事本克隆项目中实现基本的拼写检查。我想像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不交电费瞎发啥光 2024-09-06 05:57:14

如果您的编辑器基于编辑控件(如记事本),那么我认为这会很困难。通过子类化编辑控制窗口,您可以增强其 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.

冷…雨湿花 2024-09-06 05:57:14

实际上,我不确定您用来在窗口中渲染文本的方法,我认为您需要将其具体化。

如果一切都是使用 winapi/gdi 完成的(一般来说,这将是 TextOuting 当前文本块,考虑到换行等适合窗口),您应该添加另一个例程,这将处理拼写错误的单词渲染。

同样,这也取决于您保存当前文本及其参数的方式,但其想法是实现某种函数,例如 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文