Hi,
you might use my module, it works at least for OL2k. Example for
calling:
If SetFocusOnBody(Application.ActiveInspector.Caption)=True Then
' focus is set
Endif
Option Explicit
'-----------------------------------------------------------------------
-----
' Module :modBodyFocus
' DateTime :02.02.2004 09:01
' Author :Michael Bauer
' Purpose :Sets focus on an OL Inspector body.
' Tested :OL2k
'-----------------------------------------------------------------------
-----
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As
Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd _
As Long, ByVal wCmd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Function FindChildClassName(ByVal lHwnd As Long, _
sFindName As String _
) As Long
Dim lRes As Long
lRes = GetWindow(lHwnd, GW_CHILD)
If lRes Then
Do
If GetClassNameEx(lRes) = sFindName Then
FindChildClassName = lRes
Exit Function
End If
lRes = GetWindow(lRes, GW_HWNDNEXT)
Loop While lRes <> 0
End If
End Function
Public Function GetBodyHandle(ByVal lInspectorHwnd As Long) As Long
Dim lRes As Long
lRes = FindChildClassName(lInspectorHwnd, "AfxWnd")
If lRes Then
lRes = GetWindow(lRes, GW_CHILD) ' OL2000: ClassName = "#32770"
If lRes Then
lRes = FindChildClassName(lRes, "AfxWnd")
If lRes Then
lRes = GetWindow(lRes, GW_CHILD)
If lRes Then
' plain/text: ClassName="RichEdit20A", html:
ClassName="Internet Explorer_Server"
GetBodyHandle = GetWindow(lRes, GW_CHILD)
End If
End If
End If
End If
End Function
Private Function GetClassNameEx(ByVal lHwnd As Long) As String
Dim lRes As Long
Dim sBuffer As String * 256
lRes = GetClassName(lHwnd, sBuffer, 256)
If lRes <> 0 Then
GetClassNameEx = left$(sBuffer, lRes)
End If
End Function
Public Function GetInspectorHandle(ByVal sCaption As String) As Long
GetInspectorHandle = FindWindow("rctrl_renwnd32", sCaption)
End Function
Public Function SetFocusOnBody(sInspectorCaption As String) As Boolean
Dim lHwnd As Long
lHwnd = GetInspectorHandle(sInspectorCaption)
lHwnd = GetBodyHandle(lHwnd)
If lHwnd Then
SetFocusOnBody = CBool(SetForegroundWindow(lHwnd))
End If
End Function