views:

54

answers:

0

Hello,

I am a beginner in C#, and I try to get text in list box of an application but i don't know how to begin. I tried this code to get the list of IDM:

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);    
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false) ]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, StringBuilder lParam);
//
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);                
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr _Parent, IntPtr _ChildAfter, string _ClassName, string _WindowName);    

private void GetTextMonitor()
{
    IntPtr hWnd = FindWindow(null, "Internet Download Manager 5.14");                         
    IntPtr hWndList = FindWindowEx(hWnd, IntPtr.Zero, null, null);

    int rowCount = (int)SendMessage(hWndList, LB_GETCOUNT, IntPtr.Zero, IntPtr.Zero);            
    string[] lbItems = new string[rowCount];
    label1.Text = "Parent:" + hWnd + ", Child:" + hWndList;
    label2.Text = "ListRow: " + rowCount;

    for (int index = 0; index < rowCount; index++)
    {
        int len = (int)SendMessage(hWndList, LB_GETTEXTLEN, IntPtr.Zero, IntPtr.Zero);
        StringBuilder sb = new StringBuilder(len + 1); // allow for terminating zero character
        SendMessage(hWndList, LB_GETTEXT, (IntPtr)index, sb);
        lbItems[index] = sb.ToString();
        label1.Text += lbItems[index].ToString() + "\n";
    }

But I can not count the item in the list as well as their text. Please, Help me!!!!