Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling text from another app's editable control. 1

Status
Not open for further replies.

Schroeder

MIS
Sep 25, 2001
382
US
A forum search returned several threads about this but no definitive answers.
I would like to monitor the contents of another application's TextBox from within my VB app. The GetWindowText API works great for window captions but not user-editable text.

If someone knows how to capture editable text that'd be great. Otherwise, if anybody knows for a fact that this can't be done, I can give up and try a different tack.

Up 'til now, I've been using GetAsyncKeyState to catch key strokes. I've only been able to finesse it to be about 80% reliable for my purposes and continuously looping it slows the system noticeably.
 
Sure:
[tt]
Option Explicit
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
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

Public Sub PullText(hWnd As Long)
Dim CharCount As Long
Dim strText As String


CharCount = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1
strText = String(CharCount, Chr(0))
SendMessage hWnd, WM_GETTEXT, CharCount, ByVal strText

MsgBox "Edit control contains '" & Left(strText, CharCount - 1) & "'"

End Sub
 
It looks like that'll work for me. Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top