c# - 如何使在 wpf 窗口中运行的应用程序忽略单击或鼠标事件

标签 c# wpf windows unreal-engine4

目前我正在尝试在 wpf 窗口中运行虚幻 4 应用程序。但是我只希望用户看到窗口而不是单击它或使用它。为此,我尝试了各种解决方法,但似乎都没有实际效果。任何帮助将不胜感激。谢谢你。下面是我用来在 wpf 窗口中运行应用程序的代码。

    [DllImport("user32.dll", EntryPoint="GetWindowThreadProcessId",  SetLastError=true,
         CharSet=CharSet.Unicode, ExactSpelling=true,
         CallingConvention=CallingConvention.StdCall)]
    private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId); 

    [DllImport("user32.dll", SetLastError=true)]
    private static extern IntPtr FindWindow (string lpClassName, string lpWindowName);

    [DllImport("user32.dll", SetLastError=true)]
    private static extern long SetParent (IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("user32.dll", EntryPoint="GetWindowLongA", SetLastError=true)]
    private static extern long GetWindowLong (IntPtr hwnd, int nIndex);

    [DllImport("user32.dll", EntryPoint="SetWindowLongA", SetLastError=true)]
    public static extern int SetWindowLongA([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("user32.dll", SetLastError=true)]
    private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);

    [DllImport("user32.dll", SetLastError=true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

    private const int SWP_NOOWNERZORDER = 0x200;
    private const int SWP_NOREDRAW = 0x8;
    private const int SWP_NOZORDER = 0x4;
    private const int SWP_SHOWWINDOW = 0x0040;
    private const int WS_EX_MDICHILD = 0x40;
    private const int SWP_FRAMECHANGED = 0x20;
    private const int SWP_NOACTIVATE = 0x10;
    private const int SWP_ASYNCWINDOWPOS = 0x4000;
    private const int SWP_NOMOVE = 0x2;
    private const int SWP_NOSIZE = 0x1;
    private const int GWL_STYLE = (-16);
    private const int WS_VISIBLE = 0x10000000;
    private const int WS_CHILD = 0x40000000;


    /// <summary>
    /// Force redraw of control when size changes
    /// </summary>
    /// <param name="e">Not used</param>
    protected void OnSizeChanged(object s, SizeChangedEventArgs e)
    {
        this.InvalidateVisual();

       this.Width =  WpfUserAppControl.Width = 200;
       this.Height =  WpfUserAppControl.Height = 200;

        //Application.Current.MainWindow.Width = Window.GetWindow(this.AppContainer).Width;


        MoveWindow(_appWin, 100, 100, (int)WpfUserAppControl.Height, (int)WpfUserAppControl.Width, true);
    }


    /// <summary>
    /// Create control when visibility changes
    /// </summary>
    /// <param name="e">Not used</param>
    protected void OnVisibleChanged(object s, RoutedEventArgs e)
    {
        // If control needs to be initialized/created
        if (_iscreated == false)
        {

            // Mark that control is created
            _iscreated = true;

            // Initialize handle value to invalid
            _appWin = IntPtr.Zero;

            try
            {
                var procInfo = new System.Diagnostics.ProcessStartInfo(this.exeName);
                procInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(this.exeName);

                _childp = System.Diagnostics.Process.Start(procInfo);



                _childp.WaitForInputIdle();



                while (_childp.MainWindowHandle == IntPtr.Zero)
                {
                System.Threading.Thread.Sleep(10);

                }


                _appWin = _childp.MainWindowHandle;
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message + "Error");
            }

            // Put it into this form
            var helper = new WindowInteropHelper(Window.GetWindow(this.AppContainer));
            SetParent(_appWin, helper.Handle);
            AppControl.
            // Remove border and whatnot
           SetWindowLongA(_appWin, GWL_STYLE, WS_VISIBLE);

            // Move the window to overlay it on this window
            MoveWindow(_appWin, 100, 100, (int)WpfUserAppControl.Height, (int)WpfUserAppControl.Width, true);
           _childp.Exited += _childp_Exited;

           SetWindowPos(_appWin, -2, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE);
        }
    }

最佳答案

到目前为止,我找到的最佳解决方案是在加载虚幻引擎后运行另一个透明的窗口应用程序。

关于c# - 如何使在 wpf 窗口中运行的应用程序忽略单击或鼠标事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28550926/

相关文章:

c# - 无法在 cshtml 中使用内插字符串

c# - 我可以在 .NET 3.5 的代码隐藏中打印标准测试页吗?

c# - 确定 ListboxItem 在 Canvas 中的位置?

c++ - 带有多个参数的 QProcess 启动进程(blender.exe)

c# - 接收 : Ignoring updates caused by Subscribers

C#定长字符串

c# - 无法从桌面控制台应用程序访问 Azure Key Vault

wpf - 绑定(bind) slider 控件的事件

java - 打开 jar 文件时,更改 JAVA 中的外观和感觉不起作用

c++ - Boost 文件系统总是在 Windows 上返回 false