tags:

views:

404

answers:

2

Hello, I want to use SendMessage/PostMessage to send some keys to an applications textbox. I used Microsoft Spyxx to get class name of this textbox. Now I have the problem that there are several textboxes in this app with the same class-Name ("WindowsForms10.EDIT.app.0.2e0c681") and same Window-name.

How to get the handle of the right one?

PS: I'm coding in c# with Visual c# 2008 express

A: 

Well, there must be something you do know about the textboxe that you could use: For instance you could search for a textbox with a specific owner, and check what the preceding child window is... If the control has a label, you could find the label first and then find the control sitting to the right of it.

jdv
A: 

If the different hWnd values return the same results for the API functions

[DllImport( "user32.dll" )]
public static extern int GetClassNameW( HandleRef hWnd, [MarshalAs( UnmanagedType.LPWStr )] StringBuilder className, int nMaxCount );

[DllImport( "user32.dll" )]
public static extern int GetWindowTextLength( HandleRef hWnd );

[DllImport( "user32.dll" )]
public static extern int GetWindowTextW( HandleRef hWnd, [MarshalAs( UnmanagedType.LPWStr )] StringBuilder text, int maximum );

you may be stuck having to do your edits based in the position the objects exist on the form

public struct WindowPlacement {
  public int length;
  public int flags;
  public int showCmd;
  public Point minPosition;
  public Point maxPosition;
  public Rectangle normalPosition;
}

[DllImport( "user32.dll" )]
public static extern bool GetWindowPlacement( HandleRef hWnd, ref WindowPlacement position );
JDMX