Targeted
Navigation:

Technology All The Way
Iodid Weblogs
 

Standard
Navigation:

Home
FAQ
Search
Table of Contents

Email:

TryandGuess
-at-
iodid.com

Search this weblog:


Visitor Count:
Money Grubbing:

Amazon Honor System Click Here to Pay Learn More

Terms of Use

June 07, 2003

Manipulating Word and Its SpellChecker pt. 1

In an effort to reuse the Spellchecker of MS Word, I have learned how to get it to check the spelling of a word or words. I have even learned how to get it to generate suggestions. I have, however been unable to convince it to reload the custom dictionaries after I have added a word to one of them. This is very frustrating because it makes me unable to have an effective form that works like the spell-checking dialog box in Word.

Having spent more time on this issue than I would like I decided why recreate something like the Word spell checker when it is just as available directly. Thus I thought I had solved my problem. I simply programatically paste the word or words I want to check into a blank Word Doc and then run the spell checker and then retrieve the corrections from Word for my application.

Alas I have found this simple plan to have one flaw. If my application is higher than Word in the Z-order, then the spell-check dialog box is placed behind my application. So I thought, this shouldn't be hard to fix, just raise the place of Word in the z-order.

Does .net have a way to do this?
Of course not (at least as far as my research has found), but there is a way to do it in older versions of VB. That method is to manipulate the Window via the Windows API. Technically this is still possible via .Net as well so I have decided to do it this way.

Enough background. What is this entry about? To manipulate a window via the API you need it handle. Thus the link:

302281 - HOWTO: Obtain the Window Handle for an Office Automation Server Using Visual Basic .NET

Here is the most relevant part:

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop

Public Class MyApi
<DllImport("user32.dll")> Public Shared Function _
FindWindow(ByVal strClassName As String, ByVal strWindowName _
As String) As Integer
End Function
End Class

Dim xlapp As Excel.Application
Dim hwndExcel As Integer

xlapp = New Excel.Application()
xlapp.Visible = True
xlapp.Caption = "Some Window Caption"

hwndExcel = MyApi.FindWindow("XLMAIN", xlapp.Caption)

xlapp.Caption = Nothing

MsgBox("hwndExcel (" & Hex(hwndExcel) & ") has the Window handle to " & _
"Excel's Main Window." & vbCr & " Click OK to close Excel." )

xlapp.Quit()


Now I just have to adapt it to Word.

Posted by tmichael at June 7, 2003 10:30 AM
Comments
Post a comment