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 10:30 AM | Comments (0)

Good Reference

kbAlertz! is a page that lists most (all?) of the Microsoft Knowledge Base articles, relevant to Visual Studio .Net. It can be very helpful in identifying what MS has to say about an issue.

Posted by tmichael at 11:30 AM | Comments (0)

Method to cause an application to show a dialog box

Show Method

Here is how I used it:
x = WordApp.Dialogs.Item(WdWordDialog.wdDialogToolsSpellingAndGrammar).Show

Posted by tmichael at 02:18 PM | Comments (0)

Manipulating Word and Its SpellChecker pt. 1

Now that I have the handle for Word I need to make use of the Topmost function to raise it above the others. I found this page to be helpful:

VB TopMost Function

The most useful parts are:


Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40
Public Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Sub MakeTopMost(Handle As Long)
SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

Public Sub MakeNormal(Handle As Long)
SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

Posted by tmichael at 02:33 PM | Comments (0)

Bringing a specific window to the top yet again

I was still having problems so I found this page:
Create a Form that Cannot Be Activated

From It I found this that seems to work better:


Private Declare Function BringWindowToTop _
Lib "user32" (ByVal hwnd As Long) As Long

Posted by tmichael at 05:49 PM | Comments (0)

Long List of How To's

I stumbled across this list. I think it may be very helpful in the future:
Microsoft QuickStart Tutorials

Posted by tmichael at 06:04 PM | Comments (0)

June 09, 2003

Version Number

I used information from Versioning an Assembly to be able to control the version numbers of my current project.

Specifically:

imports system
imports system.reflection
Imports System.Runtime.InteropServices

<Assembly: AssemblyTitle("")>

<Assembly: AssemblyDescription("")>

<Assembly: AssemblyCompany("")>

<Assembly: AssemblyProduct("")>

<Assembly: AssemblyCopyright("")>

<Assembly: AssemblyTrademark("")>

<Assembly: CLSCompliant(True)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("41BD3203-06FC-4FF4-8A74-3C842C207D49")>

' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:

<Assembly: AssemblyVersion("1.0.0.0")>

Posted by tmichael at 03:29 PM | Comments (0)

June 21, 2003

Hide Datagrid Expanders

In the program I am developing, I wanted to show data from a table in a datagrid. This table is related to another table. As a result, this datagrid would show an expander and the name of that other table. I wanted this hidden. So I asked myself, "How do I hide the expander?" I didn't know so I searched and found the following:

Microsoft Support WebCasts

One DataGrid is designated to be the master grid and the second is designated to be the details grid. When you select an entry in the master list, all of the related child entries are shown in the details list. As you can see, there are no expanders shown on the master DataGrid. This is done by setting the AllowNavigation property of the DataGrid controls to false.

So there you have it set AllowNavigation to False. If you happen to find this useful, please link to this post as there is nothing that says to do this to hide them. I think this would be very helpful to others.

Posted by tmichael at 06:12 PM | Comments (1)

June 22, 2003

TreeNode Level

If you spend any time working with Treeviews, I can't imagine not needing this or having to invent it yourself:

Windows Forms FAQ - Windows Forms TreeView

[VB.NET]

Public Sub NodateLevel(ByVal node as TreeNode) As Integer

Dim level as Integer = 0

While Not node Is Nothing

node = node.Parent

level = level 1

End While

End Sub

I edited into this:


Private Function NodeLevel(ByVal node As TreeNode) As Integer
Dim level As Integer = 0
While Not node Is Nothing
node = node.Parent
level = level + 1
End While
End Function

Posted by tmichael at 04:55 PM | Comments (0)