【发布时间】:2009-09-28 19:00:01
【问题描述】:
我正在使用 ROT 来查找任何活动的 MSWord 实例。在某些版本的 word 中,该文档没有在表格中注册,而是注册为 NORMAL 模板,因此我无法按照 microsoft 记录的标题找到该文档。有谁知道这个的修补程序?
【问题讨论】:
标签: com automation ms-word
我正在使用 ROT 来查找任何活动的 MSWord 实例。在某些版本的 word 中,该文档没有在表格中注册,而是注册为 NORMAL 模板,因此我无法按照 microsoft 记录的标题找到该文档。有谁知道这个的修补程序?
【问题讨论】:
标签: com automation ms-word
FindWindowPartial API 对您有用吗?它将允许您搜索标题中带有 Microsoft Word 的窗口。
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
【讨论】: