Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force Dialog Box (Spell Check) to Come to Front

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
I've got a VB.NET application which I am working on which uses the Word spellchecking feature. I've tried numerous things to get the dialog box for the spellchecker to pop-up on top of all the other windows, but it doesn't work. Below is the code for the function which I have tried to make work - as you can see I tried .Show, .Active and .Topmost, but no matter what the dialog box is hidden under my windows:

Code:
Public Function CheckString(ByRef str As String) As String

        Dim app As Application = New Word.Application
        Dim doc As Document = app.Documents.Add
        app.Selection.Text = str

        Try

            Dim dlg As Word.Dialog
            dlg = app.Dialogs.Item(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar)



            Dim oldFilter As IOleMessageFilter = Nothing
            Dim nullFilter As IOleMessageFilter = Nothing
            CoRegisterMessageFilter(nullFilter, oldFilter)
            Try
                dlg.Show()
                dlg.Active()
                dlg.TopMost = True

            Finally
                CoRegisterMessageFilter(oldFilter, oldFilter)
            End Try

            app.Visible = False

            Dim docRange As Range = doc.Content

            str = docRange.Text

            str = str.TrimEnd(Environment.NewLine)

        Catch e As Exception

            System.Diagnostics.Trace.WriteLine("Spell checking...")
            System.Diagnostics.Trace.WriteLine(e.ToString)

        Finally

            doc.Close(WdSaveOptions.wdDoNotSaveChanges)
            app.Quit()

        End Try

        Return str

    End Function

Thanks,
Jeff
 
Well, the bad news is that this is a problem that's been around for years, any solutions I've seen are inconsistent workarounds at best, and Microsoft specifically says that using Word's spell check in other applications is both buggy and not supported.

Perhaps the SpellCheck class could do what you need:
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top