|
-
Jan 13th, 2002, 12:53 AM
#1
Thread Starter
Stuck in the 80s
Use the FindWindow API to get the handle of the window then use the following function to retrieve the text:
VB Code:
Public Declare Function FindWindow Lib "user32" &_
Alias "FindWindowA" (ByVal lpClassName As String, ByVal &_
lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" &_
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As &_
Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Function GetText(Window As Long) As String
Dim Cursor As String, Text As Long
Text& = SendMessage(Window&, WM_GETTEXTLENGTH, 0&, 0&)
Cursor$ = String(Text&, 0&)
Call SendMessageByString(Window&, WM_GETTEXT, Text& + 1, Cursor$)
GetText$ = Cursor$
End Function
-
Jan 13th, 2002, 12:06 PM
#2
PowerPoster
Here part of the code that Ive use it in my previous program and hope it make sense to you 
VB Code:
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
'//Find the Messenger Window handle
phWnd = FindWindow(0, "Messenger Service ")
'phWnd = FindWindow(0, "Project1")
If phWnd > 0 Then
'//Find the Static Window handle
EnumChildWindows phWnd, AddressOf EnumChildProc, ByVal 0&
End If
End Sub
Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim tmp As String
Dim wClass As String
Dim Buff As String
'//Get the Child Class Name
tmp = String(260, Chr(0))
GetClassName hWnd, tmp, 260
p1 = InStr(1, tmp, Chr(0), vbTextCompare)
If p1 > 0 Then
wClass = Left$(tmp, p1 - 1)
'//compare the class name
If StrComp(UCase(wClass), "STATIC", vbTextCompare) = 0 Then
'//Continue retrieve the Message
Buff = Space$(GetWindowTextLength(hWnd) + 1)
GetWindowText hWnd, Buff, Len(Buff)
'//Display the text
Buff = Left$(Buff, Len(Buff) - 1)
MsgBox Buff
Exit Function
End If
End If
'//Continue enumeration
EnumChildProc = 1
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|