我正在做一些关于c#的项目.我需要i从ListView窗口获取项目,通过做这样的事情我得到它的句柄
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#的例子.有帮助吗?
我试图从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)