Get ListView items from other windows z
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的更多相关文章
- Eclipse下生成.dll动态库及.a静态库使用 for Windows [z]
以后的主要工作就是做库了,将我们的C或者C++写的接口做成库,给客户端使用,因此有必要知道库的使用和制作方法.主要是在Eclipse下搞了搞,公司用的是Carbide,也差不多.库做好了,用SVN已提 ...
- System.Windows.Forms.ListView : Control
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
- 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView
原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...
- 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 ...
- C#中使用Log4net日志输出到本地文件、Textbox或Listview
网上很多配置log4net的方法,但是排行靠前的 根本就没有说明清除,导致浪费了两个小时来搞清楚如何配置,真是无语,特写此文,给那些刚接触log4net的朋友 1.参考链接:http://blog.s ...
- 【转】稍改进过的ListView,很好用哈
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...
- C#中ListView的简单使用方法
ListView是用于显示数据的,先在窗体中拉一个lisview控件,还有一些新增.修改.删除.查询按钮和文本框,控件名称为listview,按钮为btnInsert,btnUpate,btnDele ...
- [转]C# Winform ListView使用
以下内容均来自网上,个人收集整理,具体出处也难确认了,就没写出处了: 一.基本使用: listView.View = View.Details;//设置视图 listView.SmallImageLi ...
随机推荐
- java.util.regx Demo
import java.util.regex.Matcher;import java.util.regex.Pattern; public class TestRegex { public stati ...
- AJAX安全-Session做Token
个人思路,请大神看到了指点 个人理解token是防止扫号机或者恶意注册.恶意发表灌水,有些JS写的token算法,也会被抓出来被利用,个人感觉还是用会过期的Session做token更好,服务器存储, ...
- laravel1
生成模型的时候 同时生成migration文件php artisan make:model User --migration
- KISSY学习笔记(更新中)
序:身为一个JAVA开发工程师,前端代码我尽量是使用原生的JS来写的,或是使用一些JQ的开源组件(但是也只是使用,没有好好去研究过JQ这个框架).目前由于工作需要,必须要使用KISSY,打算借此机会, ...
- linux磁盘设备知识
linux分区数字编号: 1.分区数字编号1至4留给主分区或扩展分区使用,逻辑分区编号从5开始. 2.IDE硬盘设备名均以/dev/hd开头,不同硬盘编号依次是/dev/hda/./dev/hdb./ ...
- Git权威指南 读笔(1)
第四章 Git初始化: 设置Git当前用户和邮件地址: $ git config --global user.name $ git config --global user.email 设置Git命令 ...
- CODEVS 3000公路修建问题
题目描述 Description OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情况还是很糟糕.所以,OIER Associat ...
- Call Azure Queue get "The remote server returned an error: (400) Bad Request."
这几天开始研究Windows Azure, 在使用Azure Queue 的时候,CreateInfNotExists 总是抛出异常 "The remote server returned ...
- javascript高级编程笔记01(基本概念)
1.在html中使用JavaScript 1. <script> 元素 <script>定义了下列6个属性: async:可选,异步下载外部脚本文件. charset:可选, ...
- Automotive Security的一些资料和心得(6):AUTOSAR
1.1 Introduction AUTOSAR(汽车开放系统架构)是一个开放的,标准化的汽车软件架构,由汽车制造商,供应商和开发工具共同开发.它联合了汽车OEM ,供应商和开发工具供应商,其目标是创 ...