Sometimes, it would be nice to have an edit box with a spell checker and/or thesaurus built in, especially if you use edit boxes to enter longer messages (E.g. for logs, descriptions, IM messages, ...).
While searching the web, I found some free spell checkers, but most of them didn't work on Windows, or missed many language dictionaries. Then I found MySpell which is used by the free OpenOffice suite. It is distributed under a BSD license, which means you can use it in commercial applications. You just have to mention the copyright somewhere in your app.
And since MySpell is used by OpenOffice, there are dictionaries for almost every language available. And those dictionary files are compatible with the ones Mozilla uses.
I found MySpell, I started hacking on extending the
CEdit control to make good use of it. Here's what the result looks like:
To use the
- Add the files SpellEdit.h, SpellEdit.cpp and all files in the MySpell folder to your project.
- Replace all
CEdit variables with
CSpellEdit (don't forget to
#include the SpellEdit.h file).
Since the default context menu of the edit control is replaced (see PJ Arends' article here on how to do that), you might want to translate those strings (default is English). To do that, you can add the following strings to your resource stringtable:
If those strings are not present, then the default English strings will be used.
Also: if no dictionary files are found or set, then the
CSpellEdit control will do nothing, i.e. it will be exactly like the normal
CSpellEdit searches for dictionary files at startup automatically. It looks for those files in the same directory as the program is and in the /dic/ subfolder. For example in:
- c:\program files\myapp\
- c:\program files\myapp\dic\
Since there could be many dictionary files in those folders,
CSpellEdit first checks if there are dictionaries for the current user locale. If those are not found, then it looks for the English dictionaries. Example:
Current user locale is: de_CH
If you don't want to store the dictionary files in your program's folder, you can set the paths to the dictionary files with the
26.04.2004 - if found in user32.dll, the default context menu of the edit control is used.