小编b0x*_*xer的帖子

从其他窗口获取ListView项目

我正在做一些关于c#的项目.我需要iListView窗口获取项目,通过做这样的事情我得到它的句柄

IntPtr par_hWnd = API.FindWindow(null, "Form1");
IntPtr child1 = API.FindWindowEx(par_hWnd, (IntPtr)0, null, null);
Run Code Online (Sandbox Code Playgroud)

API 是我的静态类,有很多来自"user32.dll"的dllimports我能够得到这个ListView中的项目数:

IntPtr count = API.SendMessage(child1, API.LVM_GETITEMCOUNT, 0, 0);
Run Code Online (Sandbox Code Playgroud)

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

.net c# pinvoke listviewitem winforms

7
推荐指数
1
解决办法
1万
查看次数

c#中的窗口挂钩

我试图从csharp连接到其他窗口.我正在使用SetWindowsHookEx,但没有运气转换它com c ++ tc#.我在这里找到了这个帖子, 但它没有解决.问题是SetWindowsHookEx返回0.它包括我找到的最佳代码samle:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowDrawer
{
    public partial class Form1 : Form
    {
        private delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
        static IntPtr hHook;
        IntPtr windowHandle;
        uint processHandle;

        HookProc PaintHookProcedure;     

        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern System.IntPtr FindWindowByCaption(int ZeroOnly, string lpWindowName);

        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowsHookEx", SetLastError = true)]
        static extern IntPtr SetWindowsHookEx(int idHook, …
Run Code Online (Sandbox Code Playgroud)

c# setwindowshookex

6
推荐指数
2
解决办法
5117
查看次数

标签 统计

c# ×2

.net ×1

listviewitem ×1

pinvoke ×1

setwindowshookex ×1

winforms ×1