Thursday, 15 August 2013

Get listview from third party application

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> GetListBoxContents(IntPtr listBoxHwnd)
{
int cnt = (int)SendMessage(listBoxHwnd, LVM_GETITEMCOUNT,
IntPtr.Zero, null);
List<string> listBoxContent = new List<string>();
for (int i = 0; i < cnt; i++)
{
StringBuilder sb = new StringBuilder(256);
IntPtr getText = SendMessage(listBoxHwnd, LVM_GETITEMTEXT,
(IntPtr)i, sb);
listBoxContent.Add(sb.ToString());
}
return listBoxContent;
}
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 = GetListBoxContents(ks);
No data is returned, what is the problem?

No comments:

Post a Comment