ozdrgnaDiies
ozdrgnaDiies

Reputation: 1929

Cannot get TEdit handle from TPanel

I have a main window that has a TEdit and a TButton that I need the handles to. They are both inside a TPanel. My code so far is

    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
    }

This gives me the handles for the TPanel and the TButton, but 0 for the TEdit. I have no idea why this doesn't work since it follows the structure that Spy++ gives me:

Spy++ Structure of Window

Is there something I'm missing here? Do I need a different method to get the handle for TEdit? Am I using FindWindowEx wrong?

Upvotes: 2

Views: 862

Answers (1)

Mike W
Mike W

Reputation: 1284

Spy++ shows that the edit box has no text in it. Strange, even the tButton has no caption. Finding the tEdit should work the first time but based on your other question but as soon as you send some text to the edit the FindWindowEx call will fail since you're always passing "" as the text. You can pass null instead to find any match.

Upvotes: 5

Related Questions