AW: Steuerung von Fremdprogrammen mit Send Message
29.09.2014 10:12:37
Fremdprogrammen
Morgen Thomas,
Du brauchst den Handle dieser Textbox. Vielleicht hilft ja dieses weiter, das liest Controls aus drei verschiedenen Anwendungen aus.
HTH, Bernd
--
Option Explicit
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
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 SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long _
) As Long
' liest den Text eines Controls Edit aus einem Fenster
' siehe auch:
' http://www.c-plusplus.de/forum/viewtopic-var-t-is-86978-and-postdays-is-0-and-postorder-is-asc-and-start-is-0.html
' http://www.vbarchiv.net/tipps/ _
details.php?id=937
' http://www.xtremevbtalk.com/ _
showthread.php?t=284534
Sub ReadControlText()
Dim wnd As Long
' liefert die aktuelle Addresse aus einem Windows Explorer
wnd = FindWindow("ExploreWClass", vbNullString)
If wnd Then MsgBox GetControlText(wnd, "Edit")
' liefert die aktuelle URL aus einem Internet Explorer
wnd = FindWindow("IEFrame", vbNullString)
If wnd Then MsgBox GetControlText(wnd, "Edit")
' liefert den aktuellen Klassennamen aus X-Spy (http://www.x-spy.net/)
wnd = FindWindow("TXSpyMainForm", vbNullString)
If wnd Then MsgBox GetControlText(wnd, "TEdit")
End Sub
Private Function GetControlText(wnd As Long, ByVal strName As String)
Dim strBuf As String, lngBufLen As Long
Dim lngChildCount As Long
Dim wndChild As Long
Dim arwndChilds() As Long
Dim i As Long
Dim strText As String
lngBufLen = 256
strBuf = Space$(lngBufLen - 1)
lngBufLen = GetClassName(wnd, strBuf, lngBufLen)
strBuf = Left$(strBuf, lngBufLen)
If strBuf = strName Then
GetControlText = ReadText(wnd)
Exit Function
End If
lngChildCount = 0
wndChild = GetWindow(wnd, GW_CHILD)
Do While wndChild 0
lngChildCount = lngChildCount + 1
ReDim Preserve arwndChilds(1 To lngChildCount)
arwndChilds(lngChildCount) = wndChild
wndChild = GetWindow(wndChild, GW_HWNDNEXT)
Loop
For i = 1 To lngChildCount
strText = GetControlText(arwndChilds(i), strName)
If strText "" Then Exit For
Next i
GetControlText = strText
End Function
Private Function ReadText(wnd As Long) As String
Dim lngTextLen As Long
Dim strText As String
lngTextLen = SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0)
If lngTextLen = 0 Then Exit Function
lngTextLen = lngTextLen + 1
strText = Space$(lngTextLen)
lngTextLen = SendMessage(wnd, WM_GETTEXT, lngTextLen, ByVal strText)
ReadText = Left$(strText, lngTextLen)
End Function