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 Vi开发者_开发问答sual c# 2008 express
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.
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 );
精彩评论