加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 从其他窗口获取ListView项目

发布时间:2020-12-15 07:43:57 所属栏目:百科 来源:网络整理
导读:我正在做一些关于c#的项目. 我需要从ListView窗口获取我的项目,通过做这样的事情我得到它的句柄 IntPtr par_hWnd = API.FindWindow(null,"Form1");IntPtr child1 = API.FindWindowEx(par_hWnd,(IntPtr)0,null,null); API是我的静态类,有许多来自“user32.dll
我正在做一些关于c#的项目.
我需要从ListView窗口获取我的项目,通过做这样的事情我得到它的句柄
IntPtr par_hWnd = API.FindWindow(null,"Form1");
IntPtr child1 = API.FindWindowEx(par_hWnd,(IntPtr)0,null,null);

API是我的静态类,有许多来自“user32.dll”的dllimports
我能够获取此ListView中的项目数:

IntPtr count = API.SendMessage(child1,API.LVM_GETITEMCOUNT,0);

现在我需要获取item的文本,但结果必须放在LVITEM Structure中,我不知道如何正确调用SendMessage,以及如何在c#中实现LVITEM.找不到c#的例子.有帮助吗?

解决方法

我找到了WinAPI的C#包装器,似乎可以从任何窗口访问LV的内容.
ManagedWinapi
using ManagedWinapi.Windows;
using System;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a SystemWindow object from the HWND of the ListView
            SystemWindow lvWindow = new SystemWindow((IntPtr)0x6d1d38);

            // Create a ListView object from the SystemWindow object
            var lv = SystemListView.FromSystemWindow(lvWindow);

            // Read text from a row
            var text = lv[0].Title;
        }
    }
}

此外,我还分叉mwapi here并尝试添加一些新功能 – 主要集中在着色ListView行,但也添加了一些丢失的p / invokes等.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读