by Chris Beckingham (6 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Function that takes a window name and control name as a parameter and returns the text in the specified control.
API Declarations
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
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 Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Dim WindowHandle As Long
Dim ControlHandle As Long
Dim TheText As String
Dim TheTextLen As Long
Dim ret As Long
GetTheText = "An Error Has Occured"
WindowHandle = FindWindow(vbNullString, TheWindowName)
If WindowHandle = 0 Then Exit Function
ControlHandle = FindWindowEx(WindowHandle, 0, vbNullString, TheControlName)
If ControlHandle = 0 Then Exit Function
TheTextLen = SendMessage(ControlHandle, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
TheText = Space(TheTextLen)
ret = SendMessage(ControlHandle, WM_GETTEXT, ByVal TheTextLen, ByVal TheText)
TheText = Left(TheText, ret)
GetTheText = TheText
End Function
No comments have been posted about Function that takes a window name and control name as a parameter and returns the text in the speci. Why not be the first to post a comment about Function that takes a window name and control name as a parameter and returns the text in the speci.