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); } }}
using
This can be used as in
SpellCheck spellCheck = new SpellCheck();if(!spellCheck.IsCorrect(someWord)) // not correct message
SpellCheck
if(!spellCheck.IsCorrect(someWord)) // not correct message