简体   繁体   中英

FindWindowEx - Select textbox if there are several textboxes with same classname

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

好吧,您肯定对可以使用的文本框有所了解:例如,您可以搜索具有特定所有者的文本框,并检查前面的子窗口是什么...如果控件具有标签,则可以首先找到标签,然后找到位于其右侧的控件。

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 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM