【问题标题】:How can I remotely execute the ListBox1_DoubleClick event of a ListBox using WinApi/user32.dll or something similar?如何使用 WinApi/user32.dll 或类似的东西远程执行 ListBox 的 ListBox1_DoubleClick 事件?
【发布时间】:2019-12-29 01:50:52
【问题描述】:

我需要从另一个应用程序调用 ListBox1_DoubleClick 事件。

看看下面我认为应该是怎样的代码:

using System.Runtime.InteropServices;

public class RemoteControl
{
    [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    private static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);

    public void SendClickLB(string sWinTitle, int iChildHandler)
    {
        var windowHWnd = FindWindowByCaption(IntPtr.Zero, windowTitle);
        var childWindows = GetChildWindows(windowHWnd);
        IntPtr hWnd = childWindows.ToArray()[index];

        const int WM_LBUTTONDBLCLK = 0x0203;

        SendMessage(hWnd, WM_LBUTTONDBLCLK, new IntPtr(0), new IntPtr(0));
    }
}

【问题讨论】:

  • 嗨@EdPlunkett,非常感谢您的帮助。我已经在使用 ListBox 处理程序,至于在参数 lParam 中发送坐标,我将看到如何做到这一点。但是使用 WM_LBUTTONDBLCLK 它还没有工作。
  • 这可能不是很好的建议。使用 UI 自动化。
  • @EdPlunkett,我可以获取 ListBox 处理程序,我什至可以使用 LB_GETTEXT 获取 Item 的文本,但是 ListBox 事件我仍然不知道如何触发它们。
  • 使用UI Automation
  • 谢谢,伙计们,我会尽快研究 UI 自动化并利用它来解决我的问题。非常感谢你。

标签: c# winapi user32


【解决方案1】:

我能够使用 user32.dll 远程触发 ListBox 的 DbClick 事件。

我用来达到预期结果的步骤如下:

1 - 首先我必须使用 ClientToScreen (hWnd, ref point) 函数通过 Listbox 句柄获取 X、Y 坐标;

2 - 在我通过获得的坐标将鼠标移动到所需位置并使用函数 mouse_event (MouseEventFlag dwFlags, int dx, int dy, int cButtons, int dwExtraInfo) 发送 DoubleClick 之后;

非常感谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-26
    • 2021-11-04
    • 2011-05-10
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    相关资源
    最近更新 更多