|
-
Aug 3rd, 2006, 04:59 AM
#1
Thread Starter
Lively Member
Find textbox in window
Hi,
I want to use API functions to find a window that appears when I run a program. So let's assume I do that. Now there are three different textboxes in the window and I want to send some text to them. I don't want to send same text to all of them, instead one textbox should get one text string, the other one some other text string and so on. Now the problem is, how can I locate every one of those textboxes? How can I know which one is which one? I use a "Window Finder" tool that gives me the class name of every object in the window, but the textboxes have of course same class names (Edit) and I don't know what is unique for every such textbox (the handle changes from time to time, so I can't search for the handle :S).
Thanks in advance!
-
Aug 3rd, 2006, 06:19 AM
#2
Thread Starter
Lively Member
Re: Find textbox in window
Ok I made it work. This is the code that loops for 3 textboxes and fills them with text:
VB Code:
'temp is the handle for the parent window
Do While nbr <= 2
lhWndChild = FindWindowEx(temp, lhWndChild, "Edit", vbNullString)
If lhWndChild Then
nbr = nbr + 1
If nbr = 1 Then
iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "Text1")
ElseIf nbr = 2 Then
iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "Text2")
Else
iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "(""*"")")
End If
End If
Loop
bWnd = FindWindowEx(temp, ByVal 0&, "BUTTON", ByVal "Apply")
iii = SendMessage(bWnd, BM_CLICK, 0, ByVal "0")
DoEvents
But now there is a strange thing that happens after the Do-While loop. I manage to find the "Apply" button and click it, but the program gets stuck after that step (that is, after SendMessage(bWnd, BM_CLICK, 0, ByVal "0")
). Do you have any idea of what it might be?
Very grateful for help.
[Edit]: Sorry for the formatting, don't know how to write real code in here
Last edited by Striver; Aug 3rd, 2006 at 06:23 AM.
-
Aug 3rd, 2006, 07:45 AM
#3
Thread Starter
Lively Member
Re: Find textbox in window
OK I think I resolved this too 
I use PostMessage instead of SendMessage, and then it works.
-
Aug 3rd, 2006, 07:50 AM
#4
Re: Find textbox in window
 Originally Posted by Striver
[Edit]: Sorry for the formatting, don't know how to write real code in here 
Just use the vbcode tags. See my signature for an example.
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
|