|
-
Nov 18th, 2002, 04:05 AM
#1
Thread Starter
Addicted Member
Retreiving text from a application???
Hello,
I have an application with three text boxes, of which i need to get the text value of the third text box.
I am using 'FindWindowEx' API get the handle to the textbox
and 'SendMessageStr' API to retrieve the text.
I am able to retrieve the text of the first textbox. But, not of the remaining textboxes as the class name of all the textboxes as the same!!!
Can any one help me out???
Thanx.
-
Nov 18th, 2002, 04:14 AM
#2
Frenzied Member
Rather than Sendmessage you can get a textbox's text thus:
VB Code:
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function WindowText(ByVal hwnd As Long) As String
Dim sRet As String
sRet = String$(GetWindowTextLength(hwnd),0)
If GetWindowText(hwnd, sRet, Len(sRet)) Then
WindowText = sRet
End If
End Function
To get all the textboxes, find the parent window and cycle through all it's child windows with GetWindow API call.
Hope this helps,
Duncan
-
Nov 19th, 2002, 12:50 AM
#3
Thread Starter
Addicted Member
Thanx MerrionComputin,
One more question, how do I cycle through the child windows of an application?
An example would be of great help!
Mandark
-
Nov 19th, 2002, 03:03 AM
#4
PowerPoster
VB Code:
'in a module
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hwndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Sub CycleChildWindows(ByVal hwndParent As Long)
EnumChildWindows hwndParent, AddressOf EnumChildProc, ByVal 0&
End Sub
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
'print the child window
Debug.Print hwnd
'continue enumeration
EnumChildProc = 1
End Function
-
Nov 20th, 2002, 05:51 AM
#5
Hyperactive Member
hi, i am trying the same thing but I am actually facing a problem. I can only get the values of the Textboxes on the other app for the first time that the other app is loaded. That is if I change the values in the textboxes my app wont detect the changes when I call GetWindowText again. It will continue to give me the previous value of the textboxes. Any idea why this is hapenning?
thanx
-
Nov 20th, 2002, 07:30 AM
#6
PowerPoster
Try using this code instead:
VB Code:
Private Declare Function SendMessageStr Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Dim lngTextLen As Long
Dim strText As String
lngTextLen = SendMessageStr(hwndTextBox, WM_GETTEXTLENGTH, 0&, 0&)
strText = Space(lngTextLen + 1)
SendMessageStr hwndTextBox, WM_GETTEXT, lngTextLen + 1, strText
-
Nov 21st, 2002, 12:18 AM
#7
Hyperactive Member
Thanx amitabh, the code you posted above has solved my problem.
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
|