Click here to Skip to main content
15,888,521 members
Articles / Desktop Programming / MFC
Article

SpellEdit

Rate me:
Please Sign up or sign in to vote.
4.91/5 (34 votes)
25 Apr 2004CPOL2 min read 200.7K   2.7K   71   38
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:

texy
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)


Written By
Software Developer
Switzerland Switzerland
---

Comments and Discussions

 
GeneralThesaurus Problems Pin
mollweide27-Apr-04 4:15
mollweide27-Apr-04 4:15 
GeneralRe: Thesaurus Problems Pin
SteveKing27-Apr-04 6:28
SteveKing27-Apr-04 6:28 
GeneralRe: Thesaurus Problems Pin
uspoeri26-May-04 0:55
uspoeri26-May-04 0:55 
GeneralRe: Thesaurus Problems Pin
SteveKing26-May-04 1:59
SteveKing26-May-04 1:59 
GeneralRe: Thesaurus Problems Pin
elza30-Dec-04 1:11
elza30-Dec-04 1:11 
GeneralRe: Thesaurus Problems Pin
elza2-Jan-05 0:45
elza2-Jan-05 0:45 
GeneralRe: Thesaurus Problems Pin
SteveKing10-Jan-06 7:05
SteveKing10-Jan-06 7:05 
Generalabout edit control menu Pin
Paolo Messina22-Apr-04 0:04
professionalPaolo Messina22-Apr-04 0:04 
Hi,

It's not enough to write an article, but I want to share this.

Standard menus, like those of edit controls, scroll bars, and system menus, are available as resources in User32.dll.
I don't know if this is documented somewhere, or if the resource IDs change between windows versions (although it's unlikely), but on my system (XP Pro) the edit control menu has an ID of 1.

You may use tools like Resource Hacker to see what else is there.
There are some menu items with command IDs >= 32768, that appear to be used in unicode edit controls (never had a chance to see them in action though).

Well, I thought one could load that menu, which doesn't need to be localized for most sistuations, and append application specific items, as you do in this project.

Paolo

------
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)
GeneralRe: about edit control menu Pin
SteveKing22-Apr-04 0:45
SteveKing22-Apr-04 0:45 
GeneralRe: about edit control menu Pin
Paolo Messina23-Apr-04 13:32
professionalPaolo Messina23-Apr-04 13:32 
GeneralRe: about edit control menu Pin
Paolo Messina23-Apr-04 13:27
professionalPaolo Messina23-Apr-04 13:27 

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

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