This is more difficult than one might think. In order to get the information you're looking for, you have to execute the code in the same process space as the application containing the ListView control. You do that by allocating a block of memory in the target process that is large enough to hold the LVITEM structure and the string data you expect to be returned, then move that structure to the target process. The .NET Framework makes things quite a bit easier on us here with the Marshal class.

Once you've taken that into account, it's a simple matter of declaring the LVITEM structure and sending the LVM_GETITEM message to the control using the SendMessage function, as you suspected.

// P/Invoke declarationsprivateconstint LVM_FIRST =0x1000;privateconstint LVM_GETITEMCOUNT = LVM_FIRST +4;privateconstint LVM_GETITEM = LVM_FIRST +75;privateconstint LVIF_TEXT =0x0001;[DllImport("user32.dll"),CharSet=CharSet.Auto]privatestaticexternIntPtrSendMessage(IntPtr hWnd,intMsg,IntPtr wParam,IntPtr lParam);[StructLayoutAttribute(LayoutKind.Sequential)]privatestruct LVITEM
{publicuint mask;publicint iItem;publicint iSubItem;publicuint state;publicuint stateMask;publicIntPtr pszText;publicint cchTextMax;publicint iImage;publicIntPtr lParam;}

And then you would use it like this (assuming hListView is a valid handle to a ListView control):

// Declare and populate the LVITEM structure
LVITEM lvi =new LVITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax =512;
lvi.iItem =1;// the zero-based index of the ListView item
lvi.iSubItem =0;// the one-based index of the subitem, or 0 if this// structure refers to an item rather than a subitem
lvi.pszText =Marshal.AllocHGlobal(512);// Send the LVM_GETITEM message to fill the LVITEM structureIntPtr ptrLvi =Marshal.AllocHGlobal(Marshal.SizeOf(lvi));Marshal.StructureToPtr(lvi, ptrLvi,false);SendMessage(hListView, LVM_GETITEM,IntPtr.Zero, ptrLvi);// Extract the text of the specified itemstring itemText =Marshal.PtrToStringAuto(lvi.pszText);

Get ListView items from other windows z的更多相关文章

  1. Eclipse下生成.dll动态库及.a静态库使用 for Windows [z]

    以后的主要工作就是做库了,将我们的C或者C++写的接口做成库,给客户端使用,因此有必要知道库的使用和制作方法.主要是在Eclipse下搞了搞,公司用的是Carbide,也差不多.库做好了,用SVN已提 ...

  2. System.Windows.Forms.ListView : Control

    #region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...

  3. 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom

    [源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...

  4. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

  5. Reset and Clear Recent Items and Frequent Places in Windows 10

    https://www.tenforums.com/tutorials/3476-reset-clear-recent-items-frequent-places-windows-10-a.html ...

  6. C#中使用Log4net日志输出到本地文件、Textbox或Listview

    网上很多配置log4net的方法,但是排行靠前的 根本就没有说明清除,导致浪费了两个小时来搞清楚如何配置,真是无语,特写此文,给那些刚接触log4net的朋友 1.参考链接:http://blog.s ...

  7. 【转】稍改进过的ListView,很好用哈

    using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...

  8. C#中ListView的简单使用方法

    ListView是用于显示数据的,先在窗体中拉一个lisview控件,还有一些新增.修改.删除.查询按钮和文本框,控件名称为listview,按钮为btnInsert,btnUpate,btnDele ...

  9. [转]C# Winform ListView使用

    以下内容均来自网上,个人收集整理,具体出处也难确认了,就没写出处了: 一.基本使用: listView.View = View.Details;//设置视图 listView.SmallImageLi ...

随机推荐

  1. Linux内核中的通用双向循环链表

    开发中接触Linux越来越多,休息放松之余,免不了翻看翻看神秘的Linux的内核.看到双向链表时,觉得挺有意思的,此文记下. 作为众多基础数据结构中的一员,双向循环链表在各种“教科书”中的实现是相当的 ...

  2. Android NFC标签 开发深度解析 触碰的艺术

    有几天没有更新博客了,不过本篇却准备了许久,希望能带给每一位开发者最简单高效的学习方式.废话到此为止,下面开始正文. NFC(Near Field Communication,近场通信)是一种数据传输 ...

  3. JVM 优化问题

    jvm 优化问题 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...

  4. js实现完美身份证号有效性验证

    最近需要对身份证合法性进行验证,实名验证是不指望了,不过原来的验证规则太过简单,只是简单的验证了身份证长度,现在业务需要加强下身份证验证规则,网上找到了不少资料,不过都不合偶的心意,无奈只好直接写一个 ...

  5. 原生js在IE7下 向dom添加节点的一个bug, (本例为添加hidden input)

    需求是要用js向dom结构增加1个hidden用来存放要post到服务器的数据 var aspnetForm = document.getElementById("aspnetForm&qu ...

  6. numpy+scipy+matlotlib+scikit-learn的安装及问题解决

    NumPy(Numeric Python)系统是Python的一种开源的数值计算扩展,一个用python实现的科学计算包.它提供了许多高级的数值编程工具,如:矩阵数据类型.矢量处理,以及精密的运算库. ...

  7. WPF 渐隐渐现切换背景图片

    最近学习WPF,尝试着自己做一些小玩意,也遇到了一些问题,于是整理记录以便日后查阅. 我们都知道WPF可以实现一些很炫的效果,然而有时候为达到这个目的却并不是一件很容易的事情.比如:在软件中我希望能够 ...

  8. JUnit测试工具在项目中的用法

    0:33 2013/6/26 三大框架整合时为什么要对项目进行junit测试: |__目的是测试配置文件对不对,能跑通就可以进行开发了 具体测试步骤: |__1.对hibernate进行测试 配置hi ...

  9. WebService积累

    1.缺点,无法传输复杂对象:如无法序列化key/value结构的类型参数以及相关一维集合接口(Hashtable等打上标签[Serializable]即可序列化,不过继承的IDictionary并不可 ...

  10. NUTCH Exception in thread "Thread-12751" java.lang.OutOfMemoryError: PermGen space

    转载自 :http://greemranqq.iteye.com/blog/1705867转载自:http://www.cnblogs.com/xwdreamer/archive/2011/11/21 ...