Spell check as an OS service
As Operating systems are maturing different features are finding its way into it. So much so that many software are totally becoming redundant as there USP is already a core OS feature.
Recently I needed to include some spell-checking in a software that I was writing. I used interop in MS Office (Word in particular) to get this done. Since spell checking is so widely used I do think they should now become part of Windows. It'd be great if the context menu of text boxes have some think like "Check spelling" along with Cut/Copy/Paste.
The issue is not that things like spell checking is hard to do. The issue is including new dependencies. Now I have a 30 line code that uses Word for spell checking but can I rely on MS Word being installed on all machines where the software will be deployed? This is where OS support comes into play. Someone even suggested using Web-services to get this done!!! That is simply not feasible both from perf as well as security reasons...
The code I used goes as follows....
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.Reflection;
namespace SomeNameSpace
{
class SpellCheck : IDisposable
{
private ApplicationClass m_winword;
public SpellCheck()
{
m_winword = new ApplicationClass();
}
public void Dispose()
{
object savenochanges = WdSaveOptions.wdDoNotSaveChanges;
object nothing = Missing.Value;
if (m_winword != null)
m_winword.Quit(ref savenochanges, ref nothing,
ref nothing);
m_winword = null;
}
public bool IsCorrect(string word)
{
object nothing = Missing.Value;
return m_winword.CheckSpelling(word,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing);
}
}
}
This can be used as in
SpellCheck spellCheck = new SpellCheck();
if(!spellCheck.IsCorrect(someWord))
// not correct message
Comments
- Anonymous
March 15, 2006
Great idea, really!
But! Maybe being a part of some framework is better choice? I mean .Net framework surely.
IMHO, in the case of OS service spell checking would be platform dependent. - Anonymous
March 16, 2006
When I run this example I receive this error:
"Cannot find proofing tools for Croatian. If you have the proofing tools, try installing or re-installing them.nContact your local reseller to obtain Office Proofing Tools. For more information, see the Microsoft Office Site
."
I am from Croatia and when I try this:
int i = winwrd.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDInstall);
("i" is set to 1050 (language ID for Croatia))
i = winwrd.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDExeMode);
("i" is set to 0 (language ID for English))
I suppose I can solve this problem if I reinstall the Word, but Is there any other way to solve this problem? - Anonymous
March 16, 2006
You need not reinstall Word but you do need to to install the language support. - Anonymous
March 16, 2006
I know that I need additional tools for Croatian, but I want to be able to make English spell-check. On my computer, example is always trying to make Croatian spell-check (probably because it is install language in Word). If I switch default language in Word from Croatian to English, I am then able to make english spell-check in Word but I am still not able to make that in your example. - Anonymous
June 04, 2006
The comment has been removed - Anonymous
June 12, 2006
I want to place comboBox
so user can select language for spell check
Plz help !!!!!