Ishaq Gi
Ishaq Gi

Reputation: 103

How to read a Child Window

I am using this code to read child windows of an application

  //Parent Intptr = MainWindow();  ///Caption of main window = "Terminal"

    public void GetWindows(IntPtr ParentWindowHandle)
    {
        string str = "SysListView32";
        string str2 = "";
        ParentWindowHandle = functions.FindWindowEx(ParentWindowHandle, (IntPtr)(0), ref str, ref str2);
        IntPtr[] ptrArray2 = new IntPtr[11];
        int i = 0;
        IntPtr window = functions.GetWindow(ParentWindowHandle, 5);
        while (!window.Equals(IntPtr.Zero))
        {
            str = "SysListView32";
            str2 = "";
            ptrArray2[i] = functions.FindWindowEx(window, ptrArray2[i], ref str, ref str2);
            int len = functions.SendMessage(window, 14, IntPtr.Zero, IntPtr.Zero);
            if (len > 0)
            {
                len++;
                StringBuilder lParam = new StringBuilder(len);
                functions.SendMessage(window, 13, (IntPtr)len, lParam);
                cmb_profile.Items.Add(lParam.ToString());
            }
            window = functions.GetWindow(window, 2);
            i++;
        }
    }

I am getting the windows

A)GBPUSD,H4
B)GBPUSD,H1
C)GBPUSD,Daily.

But I am not getting the Market Watch: 16:24:53.

Later I took the Caption Market Watch: 16:24:53 as Parent IntPtr but I am not getting any child window.

I want to read the symbol,Bid,Ask Columns and the list contents because it updates for every second and i want to store the rate in a database file.

There would be great appreciation if someone could help me.

Thanks In Advance.

Upvotes: 1

Views: 101

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

First of all, in order to make sense of this, you must declare some message constants to avoid using magic constants in your code.

The next step that you plan, reading the list view content, is tricky using your current strategy. You need to use LVM_GETITEMTEXT to read the content. But that requires you to pass a pointer to an LVITEM struct. And the kicker is that the struct must be allocated in the address space of the target process. This requires the use of the following APIs: OpenProcess, VirtualAllocEx, WriteProcessMemory, ReadProcessMemory.

This technique is possible and is known to work. There are countless examples of it that can be found with websearch. However, the details are quite tricky, especially if you are not an expert Win32 programmer. Combine that with the awkwardness of low-level programming in C# and you have a recipe for mistakes.

There is another, better way: UIAutomation.

Upvotes: 2

Related Questions