C# HwndSource 捕获鼠标事件和键盘敲击

问题描述

我有一个 WPF 窗口,在这个窗口中加载了一个在其他进程中运行的子窗口,并使用以下几行将 WPF 窗口设置为父窗口

var helper = new WindowInteropHelper(this);
SetParent(ffplay.MainWindowHandle,helper.Handle); 

现在该进程正在 WPF 窗口之上运行。每当用户在子窗口上执行操作时,我都想在 WPF 代码隐藏类中捕获键盘事件和鼠标事件。 在 WPF 窗口的构造函数中创建并启动子进程。

 public partial class MainWindow: Window
  {
     private Process ffplay;
    [DllImport("user32")]
    private static extern IntPtr SetParent(IntPtr hWnd,IntPtr hWndParent);
    public Window1()
    {
        InitializeComponent();
        ffplay = new Process();
        ffplay.StartInfo.FileName = "ffplay.exe";
        ffplay.StartInfo.Arguments = "ios_1.mp4";
        var f = ffplay.Start();
        try

        {
            var helper = new WindowInteropHelper(this);
            SetParent(ffplay.MainWindowHandle,helper.Handle);
                       
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error--->" + ex.Message);
        }
    }
            
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)