Results 1 to 8 of 8

Thread: [RESOLVED] Using Winspector or Spy++

  1. #1

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Resolved [RESOLVED] Using Winspector or Spy++

    I want to type text in a text box, but when I run Winspector (similar to Spy++), the class is listed as Edit. The only problem is that another text box is listed as edit too and it always puts text in the wrong box. How can I tell which text box is which?

  2. #2

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Using Winspector or Spy++

    I should clarify, I want to have my VB program paste text in a text box of another program. I'm using PostMessage to send the text to the text box and it works well, I just can't get the text into the correct text box because both have the same class name. There are 2 text boxes on the form of the other program and when I send the text, it goes to the first text box instead of the second text box. I don't know how else to specify the text box other than by the class name.

    I was using Winspector to see if there was any further way to specify the exact text box. Any help would be greatly appreciated!

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Using Winspector or Spy++

    Well SpyXX returns more than just the Class Name. It returns, object caption, object dimensions, coordinates, hwnd & style. Can you use any of that criteria to differentiate between the TextBoxes?
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  4. #4

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Using Winspector or Spy++

    It's possible that style might help, but not that I know of. I'm not sure how to refer to the style or even if I can. The other problem that I have is that the form closes when it does not have focus. I didn't build this program so I can't modify it. So when I try to find it's properties with Spy++, the form closes as soon as I click on Spy++. Winspector is nice because it actively gives you information as soon as it is launched. This way I can open the program and click in the text box and see the info. I wish there was a way to say "go to next 'Edit' text box."

  5. #5
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Using Winspector or Spy++

    I doubt that Spyxx is closing. The 'Find Window' is probably hiding behind another window.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  6. #6

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Using Winspector or Spy++

    Quote Originally Posted by CDRIVE
    I doubt that Spyxx is closing. The 'Find Window' is probably hiding behind another window.
    No, Spy++ isn't closing... the program that I want to send text to is closing when it's not in focus. It's a form where you add a username and password... let me call it PasswordBox. If I launch PasswordBox and click over to Spy++, PasswordBox closes.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Winspector or Spy++

    Quote Originally Posted by BrianPaul
    I should clarify, I want to have my VB program paste text in a text box of another program. I'm using PostMessage to send the text to the text box and it works well, I just can't get the text into the correct text box because both have the same class name. There are 2 text boxes on the form of the other program and when I send the text, it goes to the first text box instead of the second text box. I don't know how else to specify the text box other than by the class name.
    One way to do this, assumption below applies. Every control should also have a separate control id which is used in window messaging to help the parent control know which child is sending it a message or which child has recieved/processed a message. Also most windows have some static controls that are not created dynamically, I would think your password window is such a window. Therefore, if you can get the control id, you can then determine which is the right one to postmessage to. You would simply query each Edit control in the window until one matched the control id.

    Here is the assumption: the control id is static. This should be tested by querying the password window in multiple sessions. If you open the window, say 10 times, and the control id is the same all 10 times, you can be pretty sure it is static vs dynamic.

    How do you get the id? Once you know the hWnd of the Edit window use the code below. How do you know which edit control to start with? You probably don't unless you can view it in spy++ or other tools. If you can't, you can get the 1st edit control, cache its id, try postmesssage. If it went to the right box, cool. If not, try the 2nd one, etc. FindWindowEx will return each edit control within the same parent.
    Code:
    Dim editHwnd As Long, nextHwnd As Long, cID As Long
         ' supply the parent/password window's hWnd below as pHwnd
         Do 
             nextHwnd = FindWindowEx(pHwnd, editHwnd, "Edit", vbNullString)
             If nextHwnd=0& Then Exit Do
             editHwnd = nextHwnd
             cID = GetWindowLong(editHwnd, GWL_ID)
             Debug.Print "Edit hWnd "; editHwnd; " ID is "; cID
         Loop
    ' now you'll have a list of edit control windows & their IDs within the parent window.
    ' run several times to see if the control id changes or not, the editHwnd will probably change, but no biggie.
    Code:
    ' Declarations
    Private Const GWL_ID As Long = -12
    Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Alternatively, if dynamic control ids are used, you can send it to the 1st, 2nd, 3rd, etc, edit control on the window, only if the target is always in the same zOrder.
    Last edited by LaVolpe; Dec 19th, 2008 at 05:27 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Using Winspector or Spy++

    Quote Originally Posted by LaVolpe
    Alternatively, if dynamic control ids are used, you can send it to the 1st, 2nd, 3rd, etc, edit control on the window, only if the target is always in the same zOrder.
    After running your code, it appears that the first edit control is static and the second is dynamic. I didn't create this program that I'm sending text to so I don't know how it was coded, but I find it very strange that the edit controls wouldn't be either both static or both dynamic. It makes me wonder if I'm doing something wrong, but I copied your code so I think it's right. The first output reports the same numbers every time and the second output gives different numbers every time.

    Anyway, I tried what you said and sent the text to the 2nd edit control and it worked perfect! Thanks LaVolpe! I couldn't have gotten this working without your help!

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