AW: mal etwas schwieriges...
16.08.2009 11:03:39
Nepumuk
Hallo Tino,
so?
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByRef lpRect As RECT) As Long
Private Declare Function EnumChildWindows Lib "user32.dll" ( _
ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const GC_CLASSNAMEMSEXCEL = "XLMAIN"
Private Const GC_CLASSNAMEMSEXCEL7 = "EXCEL7"
Private udtRect As RECT
Public Sub Test()
Dim lngHwnd As Long
lngHwnd = FindWindow(GC_CLASSNAMEMSEXCEL, Application.Caption)
Call EnumChildWindows(lngHwnd, AddressOf WndEnumChildProc, 0)
With udtRect
MsgBox "Left " & .Left & vbLf & "Top " & .Top & vbLf & _
"Right " & .Right & vbLf & "Bottom " & .Bottom
End With
End Sub
Private Function WndEnumChildProc(ByVal lngHwnd As Long, ByVal lngParam As Long) As Long
Dim strTempWindowText As String * 512, strTempClassName As String * 50
Dim strClassName As String, strWindowText As String
Dim lngTextlen As Long
lngTextlen = GetWindowTextLength(lngHwnd)
Call GetWindowText(lngHwnd, strTempWindowText, lngTextlen + 1)
strWindowText = Left$(strTempWindowText, InStr(1, strTempWindowText & vbNullChar, vbNullChar) - 1)
Call GetClassName(lngHwnd, strTempClassName, 50)
strClassName = Left$(strTempClassName, InStr(1, strTempClassName & vbNullChar, vbNullChar) - 1)
If strClassName = GC_CLASSNAMEMSEXCEL7 Then
If strWindowText = ThisWorkbook.Name Then
Call GetWindowRect(lngHwnd, udtRect)
WndEnumChildProc = 0
End If
Else
WndEnumChildProc = 1
End If
End Function
Gruß
Nepumuk