2012-01-02 83 views
2

我有一个主窗口,它有一个TEdit和一个TButton,我需要这些句柄。他们都在TPanel内。我的代码到目前为止是无法从TPanel获得TEdit句柄

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的手柄。我不知道为什么,这并不工作,因为它遵循间谍++给我的结构:

Spy++ Structure of Window

有我丢失的东西吗?我需要一种不同的方法来获得TEdit的句柄吗?我使用FindWindowEx错误吗?

+0

如果你想从.NET做UI自动化,White项目可能会简化你的工作:http://white.codeplex.com/ – 2012-01-02 03:41:07

+0

我不认为TEdit的父窗口是面板...尝试IntPtr edithWnd = Window.FindWindowEx(hWnd,IntPtr.Zero,“TEdit”,“”); – ComputerSaysNo 2012-01-02 04:34:04

+0

P.S.我也注意到,你在截图中有一个TMemo但不是TEdit,是否可以用备忘录代替TEdit字段? – ComputerSaysNo 2012-01-02 04:38:02

回答

5

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

+0

你又帮了我一次。发送null而不是“”让我立即处理。非常感谢你。 – ozdrgnaDiies 2012-01-02 05:43:40