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.

  1. // 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
  2. {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):

  1. // Declare and populate the LVITEM structure
  2. LVITEM lvi =new LVITEM();
  3. lvi.mask = LVIF_TEXT;
  4. lvi.cchTextMax =512;
  5. lvi.iItem =1;// the zero-based index of the ListView item
  6. lvi.iSubItem =0;// the one-based index of the subitem, or 0 if this// structure refers to an item rather than a subitem
  7. 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. jQuery 1.7以后 jQuery2 新元素绑定事件on替代live

    最近做了一个类别动态加载的功能,jQuery版本用的是2.02. 绑定事件jQuery1.7之前用的是live或者是bind.新版的jQuery新增了on方法 由于子类别是动态加载的,默认是不会有事件 ...

  2. JDBC-ODBC桥接访问SQLServer2008数据库

    来源:十二随风博客 将对JDBC API的调用,转换为对另一组数据库连接API的调用优点:可以访问所有ODBC可以访问的数据库缺点:执行效率低.功能不够强大 (1)建立数据源,注意系统DNS才行,用户 ...

  3. Asp.Net细节性问题精萃

    1.<%=…%>与<%#… %>的区别: 答:<%=…%>是在程序执行时调用,<%#… %>是在DataBind()方法之后被调用 2.控件接收哪些类型 ...

  4. PHP学习笔记(5) - 选择一个合格的框架

    作为一个合格的PHP开发框架,个人觉得起码需要满足以下几点. 一.上梁不正下梁歪,好的框架首先自身要有良好的编码规范和文件目录结构,代码要易于阅读理解. 二.为了可以更好地适应OOP,框架必须可以提供 ...

  5. 根据版本的不同整理所有的绿色SQL Server

    在这篇论坛文章中,读者可以了解到如何根据不同的SQL Server版本,整理出所有版本的绿色SQL Server的具体方法,详细内容请参考下文: 1. Sqlservr.exe 运行参数 Sql Se ...

  6. 自己写的Python数据库连接类和sql语句拼接方法

    这个工具类十分简单和简洁. sql拼接方法 # encoding=utf-8 from django.http import HttpResponse from anyjson import seri ...

  7. mvc框架下,怎样用cookie实现下次自动登录

    登录时有个下次自动登录的checkBox.点了它下次就可以自动登录了 具体流程我都晓得,就是细节的地方有些搞不定.我只要解决3个问题: (1)登录时如果点了checkbox,则在本机产生一个cooki ...

  8. 重置mysql密码

    如何修改mysql root密码 忘记MySQL ROOT密码是在MySQ使用中很常见的问题,可是有很多朋友并不会重置ROOT密码,那叫苦啊,特写此文章与大家交流: 1.编辑MySQL的配置文件:my ...

  9. JavaScript的OOP编程2

    我做了一个observer的设计模式实现 version1 // -------------------------------------------------- function Subject ...

  10. JAVA入门第一季(mooc-笔记)

    笔记相关信息 /** * @subject <学习与创业>作业1 * @author 信管1142班 201411671210 赖俊杰 * @className <JAVA入门第一季 ...