I am using the ROT to find any active MSWord instances. In some versions of word the document does not get registered in the table, instead it is registered as the NORMAL template and so I can not find the document by it's title as documented by microsoft. Anyone know of a hotfix for this?
A:
Is FindWindowPartial API any use to you? It will allow you to search for windows with Microsoft Word in the title.
Option Explicit
Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Function FindWindowPartial(ByVal Title As String) As String
Dim hWndThis As Long
hWndThis = FindWindow(vbNullString, vbNullString)
While hWndThis
Dim sTitle As String, sClass As String
sTitle = Space$(255)
sTitle = Left$(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle)))
If InStr(sTitle, Title) > 0 Then
FindWindowPartial = sTitle & "|" & FindWindowPartial
End If
hWndThis = GetWindow(hWndThis, GW_HWNDNEXT)
Wend
End Function
Remou
2009-09-01 16:43:03