简体   繁体   中英

Get listview from third party application

I'm trying to get a listview from a third party application, here's how I'm trying to accomplish this

   [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;
    }

Then I use UISpy to get the handle for the listview property on the application and use the following code to populate my applications listbox:

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

No data is returned, what is the problem?

You are passing a StringBuffer to something that is expecting a particular structure, as per http://msdn.microsoft.com/en-us/library/windows/desktop/bb761055(v=vs.85).aspx

You should take a look at Getting Text from SysListView32 in 64bit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM