简体   繁体   English

单词下的波浪线(Win32)

[英]Squigglly line under a word (Win32)

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. 我想像Word一样,用波浪线在拼写错误的单词下划线。 I think I need to use GDI and draw on the text field, but I'm not sure how to draw on controls. 我想我需要使用GDI并在文本字段上绘图,但是我不确定如何在控件上绘图。 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. 通过子类化编辑控件窗口,您可能可以增强其WM_PAINT处理。 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. 您可能可以使用Rich Edit控件(就像写字板一样)并调整拼写错误的单词的样式。 I've never used Rich Edit, so I can't help with the details. 我从未使用过Rich Edit,因此无法提供详细信息。

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. 如果一切都使用winapi / gdi完成(通常来说,这是在当前文本块中使用TextOut ,考虑到自动换行适合窗口的大小等),则应添加另一个例程,该例程将处理拼写错误的单词。

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. 同样,这也取决于您保存当前文本及其参数的方式,但是其想法是实现某种功能,如RenderMisspelledWord(...) ,它将采用您的通用文本处理类或某种渲染器类,或者偶数(X, Y, Length)作为参数。 This function would be called from a more general Render method, which would be called from WM_PAINT handler. 该函数将从更通用的Render方法调用,该方法将从WM_PAINT处理程序调用。

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. 它的作用还取决于您的记事本体系结构,但是,例如,在最后一种情况下,将需要使用GDI(线性)例程绘制* / \\ / \\ // \\ *下划线的部分。

Generally speaking, every other case (with handling classes) would lead to the following action too, but with higher level of abstraction. 一般而言,其他所有情况(带有处理类)也将导致以下操作,但抽象级别更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM