c# - 无法从 TPanel 获取 TEdit 句柄

标签 c# delphi winapi handle

我有一个主窗口,其中有一个 TEdit 和一个 TButton,我需要它们的句柄。它们都位于 TPanel 内。到目前为止我的代码是

    public void SendPacket(string packet)
    {
        IntPtr hWnd = Window.FindWindow(null, "AlissaAnalyzer");
        IntPtr panel = Window.FindWindowEx(hWnd, IntPtr.Zero, "TPanel", "");
        IntPtr edithWnd = Window.FindWindowEx(panel, IntPtr.Zero, "TEdit", "");
        IntPtr buttonhWnd = Window.FindWindowEx(panel, IntPtr.Zero, "TButton", "");
        //Do stuff with handles
    }

这为我提供了 TPanel 和 TButton 的句柄,但 TEdit 的句柄为 0。我不知道为什么这不起作用,因为它遵循 Spy++ 给我的结构:

Spy++ Structure of Window

我在这里缺少什么吗?我是否需要不同的方法来获取 TEdit 的句柄?我使用 FindWindowEx 是否错误?

最佳答案

Spy++ 显示编辑框中没有文本。奇怪的是,即使 tButton 也没有标题。第一次查找 tEdit 应该可以工作,但根据您的其他问题,但一旦您发送一些文本到编辑,FindWindowEx 调用就会失败,因为您总是传递“”作为文本。您可以传递 null 来代替查找任何匹配项。

关于c# - 无法从 TPanel 获取 TEdit 句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697178/

相关文章:

delphi - 为什么在TObject中使用“T”前缀?

c# - Xamarin 支持 Apple TLS(不是 Mono TLS)的 SNI?

c# - ViewModel 如何与其自己的 View 通信

c# - MVC 批量编辑 - Linq to Sql 列表保存

c# - 我应该关闭 Assembly.GetManifestResourceStream 返回的流吗?

delphi - 使用 GdiPlus 卸载 DLL 时程序挂起

Delphi 和 WMI 网络

winapi - 如何登录win32 c++到Visual Studio输出窗口?

c++ - win32 项目的错误 C2146

将 char 转换为 LPCWSTR