Results 1 to 4 of 4

Thread: Find textbox in window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    126

    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!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    126

    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:
    1. 'temp is the handle for the parent window
    2. Do While nbr <= 2
    3.      lhWndChild = FindWindowEx(temp, lhWndChild, "Edit", vbNullString)
    4.      If lhWndChild Then
    5.           nbr = nbr + 1
    6.           If nbr = 1 Then
    7.                iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "Text1")
    8.           ElseIf nbr = 2 Then
    9.                iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "Text2")
    10.           Else
    11.                iii = SendMessage(lhWndChild, WM_SETTEXT, 0, ByVal "(""*"")")
    12.           End If
    13.      End If
    14. Loop
    15. bWnd = FindWindowEx(temp, ByVal 0&, "BUTTON", ByVal "Apply")
    16. iii = SendMessage(bWnd, BM_CLICK, 0, ByVal "0")
    17. 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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    126

    Re: Find textbox in window

    OK I think I resolved this too
    I use PostMessage instead of SendMessage, and then it works.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Find textbox in window

    Quote 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
  •  



Click Here to Expand Forum to Full Width