Click here to Skip to main content
Click here to Skip to main content
Go to top

SpellEdit

, 25 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A CEdit control with a spell checker and thesaurus.

Sample Image - main.jpg

Introduction

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:

spellchecker

thesaurus

Usage

To use the CSpellEdit control:

  1. Add the files SpellEdit.h, SpellEdit.cpp and all files in the MySpell folder to your project.
  2. 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:

  • IDS_SPELLEDIT_UNDO
  • IDS_SPELLEDIT_COPY
  • IDS_SPELLEDIT_CUT
  • IDS_SPELLEDIT_DELETE
  • IDS_SPELLEDIT_PASTE
  • IDS_SPELLEDIT_SELECTALL

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 CEdit control.

Dictionaries

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
try myapp\de_CH.*
try myapp\dic\de_CH.*
try myapp\de_DE.*
try myapp\dic\de_DE.*
try myapp\en_US.*
try myapp\dic\en_US.*

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 SetDictPaths() and SetThesaurPaths() methods.

Updates

26.04.2004 - if found in user32.dll, the default context menu of the edit control is used.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SteveKing
Software Developer
Switzerland Switzerland
---

Comments and Discussions

 
QuestionDebug Assertion Failure! PinmemberMember 810351615-May-13 9:55 
QuestionCRichEditCtrl Pinmemberandwan05-Nov-12 0:18 
GeneralHTML error PinmemberWilliam Winner4-Feb-10 8:04 
GeneralAre there any ports of MySpell Pinmemberzdacom13-Aug-09 19:39 
QuestionDude the ese wont shoe the red underlines? Pinmembermrtutorial0826-Aug-08 6:28 
GeneralInteresting Pinmembergaraber13-Dec-06 5:56 
Questionhunspell ? Pinmembergogac21-Jun-06 14:09 
QuestionAnyone got this to compile???? PinmemberTim Hutzler14-Mar-06 7:29 
GeneralPermission to use SpellEdit Pinmemberkeith27033-Jan-06 5:21 
QuestionMySpell PinmemberHesham Desouky28-Sep-05 9:07 
GeneralAdding new words to the dictionary files Pinmemberkeith270319-May-05 0:17 
GeneralRe: Adding new words to the dictionary files Pinmemberm00m0019-May-05 16:16 
Generalmemory leak when performing NGRAM suggestion Pinmemberm00m0016-May-05 19:11 
Generalcode can not compiled by VS.Net 2002 Pinmemberm00m0010-May-05 18:55 
GeneralRe: code can not compiled by VS.Net 2002, nevermind PinsussAnonymous11-May-05 1:34 
GeneralRe: code can not compiled by VS.Net 2002, nevermind Pinmemberm. bergman16-Jun-05 14:27 
Generalhelp Pinmemberrjnl21-Mar-05 9:12 
GeneralRe: help PinmemberEd K1-May-05 14:30 
GeneralRe: help Pinmemberrjnl2-May-05 13:39 
Generalhelp Pinmemberrjnl21-Mar-05 9:11 
GeneralPatch Pinmembermarren1-May-04 2:48 
GeneralGPL Dictionary PinmemberBoazHarrosh27-Apr-04 21:52 
GeneralRe: GPL Dictionary PinmemberSteveKing28-Apr-04 3:47 
GeneralRe: GPL Dictionary PinsussAnonymous18-May-05 2:49 
GeneralRe: GPL Dictionary PinmemberBoazHarrosh18-May-05 3:57 
GeneralRe: GPL Dictionary Pinmemberm00m0019-May-05 18:36 
GeneralRe: GPL Dictionary PinmemberEd K4-Jun-05 8:16 
GeneralThesaurus Problems Pinmembermollweide27-Apr-04 4:15 
GeneralRe: Thesaurus Problems PinmemberSteveKing27-Apr-04 6:28 
GeneralRe: Thesaurus Problems Pinmemberuspoeri26-May-04 0:55 
GeneralRe: Thesaurus Problems PinmemberSteveKing26-May-04 1:59 
GeneralRe: Thesaurus Problems Pinmemberelza30-Dec-04 1:11 
GeneralRe: Thesaurus Problems Pinmemberelza2-Jan-05 0:45 
GeneralRe: Thesaurus Problems PinmemberSteveKing10-Jan-06 7:05 
Generalabout edit control menu PinmemberPaolo Messina22-Apr-04 0:04 
GeneralRe: about edit control menu PinmemberSteveKing22-Apr-04 0:45 
GeneralRe: about edit control menu PinmemberPaolo Messina23-Apr-04 13:32 
GeneralRe: about edit control menu PinmemberPaolo Messina23-Apr-04 13:27 
Hi John,
 
That's exactly what I have on XP Pro ITA (SP1). Also, if you look at the other menu IDs you may guess they have a special meaning, because they're not sequential and they're simple bits combinations, with only 1 or 2 bits set (1,4,64,80,...) and this to me reinforces the thesis of common IDs on all platforms (at least where the corresponding menu is supported).
 
Anyway, we'll just have to check the broader range of platforms possible to be sure. Wink | ;)
 
Thanks for the report,
Paolo
 
p.s. a side note on the code sample: I think you can use GetModuleHandle in place of LoadLibrary and save a FreeLibrary, since we are subclassing an edit control User32.dll must be there already!
And what are you doing with an italian copy of w2k? (just curious) Smile | :)
 
------
Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 26 Apr 2004
Article Copyright 2004 by SteveKing
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid