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. 【HeadFirst设计模式】7.适配器模式与外观模式

    今晚学习完第七章,顺便做一下知识备忘. 适配器模模式: 定义:将一个类的接口,转换成客户期望的另一个接口.适配器让原本接口不兼容的类可以合作无间. 对象适配器: 类适配器: 外观模式: 提供了一个统一 ...

  2. Sql语句批量更新数据(多表关联)

    最近在项目中遇到一个问题,原来设计的功能是不需要一个特定的字段值depid的,但是新的功能需要根据depid来展现,于是出现了这样一个问题,新增加的数据都有正确的depid,而原来的大量的数据就没有d ...

  3. PHP+Ajax 异步通讯注册验证

    HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  4. 基于等待队列及poll机制的按键驱动代码分析和测试代码

    按键驱动分析: #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> ...

  5. 泛型转Datatable

    //自定义扩展方法 public static class ExtMethod { //泛型转为DataTable public static DataTable AsDataTable<T&g ...

  6. linux管道的容量和内部组织方式

    1.管道容量  count=65536,即64KB #include<stdio.h> #include<sys/types.h> #include<unistd.h&g ...

  7. 关于博客名“大话济公”的说明

    其实本来没打算起这个名字的,换了几个名字都被占用了(无语啊...).最近呢,我在研究<济公传>,对于济公的传说比较喜欢,尤其是这个任务,诙谐幽默,同时有时时刻刻在帮助有困难的群众,虽然是个 ...

  8. Git权威指南 读笔(4)

    第12章 改变历史: $ git commit --amend -m "Remove hello.h, which is useless." 修改提交说明 $ git log -- ...

  9. XSS传染基础——JavaScript中的opener、iframe

    最近研究XSS,根据etherDream大神的博客 延长XSS生命周期 写了一个子页面父页面相互修改的demo. 一. 子页面.父页面相互修改——window.opener.window.open 在 ...

  10. 微软Hololens学院教程-Hologram 212-Voice(语音)【微软教程已经更新,本文是老版本】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...