FindWindowEx - 如果有多个具有相同类名的文本框,则选择文本框

发布于 2024-08-20 07:59:25 字数 228 浏览 3 评论 0原文

我想使用 SendMessage/PostMessage 将一些键发送到应用程序文本框。我使用 Microsoft Spyxx 来获取此文本框的类名。现在我遇到的问题是,此应用程序中有多个文本框具有相同的类名(“WindowsForms10.EDIT.app.0.2e0c681”)和相同的窗口名称。

如何获得合适的手柄?

PS:我正在使用 Visual c# 2008 express 使用 c# 进行编码

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏剧牡丹亭 2024-08-27 07:59:25

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

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.

—━☆沉默づ 2024-08-27 07:59:25

如果不同的 hWnd 值返回相同的 API 函数结果,

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

您可能不得不根据对象在表单上存在的位置进行编辑

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

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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文