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.InteropPublic Class MyApi
<DllImport("user32.dll")> Public Shared Function _
FindWindow(ByVal strClassName As String, ByVal strWindowName _
As String) As Integer
End Function
End ClassDim xlapp As Excel.Application
Dim hwndExcel As Integerxlapp = 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.
