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

坚强是说给别人听的谎言 提交于 2019-12-11 07:22:07

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/2176710/findwindowex-select-textbox-if-there-are-several-textboxes-with-same-classname

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!