从第三方应用程序获取列表视图

时间:2013-08-15 21:21:58

标签: c# listview

我正在尝试从第三方应用程序获取列表视图,这是我如何尝试实现此目的

   [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
    const int LVM_GETITEMCOUNT = 0x018B;
    const int LVM_GETITEMTEXT = 0x0189;

    // Get ListBox contents hwnd
    private List<string> GetListViewContents(IntPtr listviewHwnd)
    {
        int cnt = (int)SendMessage(listviewHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, null);
        List<string> listViewContents = new List<string>();
        for (int i = 0; i < cnt; i++)
        {
            StringBuilder sb = new StringBuilder(256);
            IntPtr getText = SendMessage(listviewHwnd, LVM_GETITEMTEXT, (IntPtr)i, sb);
            listViewContents.Add(sb.ToString());
         }
        return listViewContents;
    }

然后我使用UISpy来获取应用程序上listview属性的句柄,并使用以下代码填充我的应用程序列表框:

     IntPtr ks = new IntPtr(0x00040FA8); // temp handle for the 3rd party listview
     listBox1.DataSource = GetListViewContents(ks);

没有返回数据,问题是什么?

1 个答案:

答案 0 :(得分:0)

根据http://msdn.microsoft.com/en-us/library/windows/desktop/bb761055(v=vs.85).aspx

,您正在将StringBuffer传递给期望特定结构的东西

你应该看看Getting Text from SysListView32 in 64bit