微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在做一些关于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等.

原文地址:https://www.jb51.cc/csharp/99321.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐