-1

I need to invoke the ListBox1_DoubleClick event from another application.

Look below how I think that should be the code:

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));
    }
}

1 Answers1

0

I was able to trigger the ListBox's DbClick event remotely using user32.dll.

The steps I used to reach the expected result were as follows:

1 - First I had to get the X, Y coordinates through the Listbox handle using the ClientToScreen (hWnd, ref point) function;

2 - After I got through the coordinates obtained to move the mouse to the desired position and send the DoubleClick using the function mouse_event (MouseEventFlag dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

Many Thanks.