Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';wpf容器上的t主机exe_C#_Wpf_Winforms_Vb6_Exe - Fatal编程技术网

C# Can';wpf容器上的t主机exe

C# Can';wpf容器上的t主机exe,c#,wpf,winforms,vb6,exe,C#,Wpf,Winforms,Vb6,Exe,(这不是评论中解释的重新发布) 我的目的是在WPF中的容器中托管一个旧的.exe(由VB6生成的一个单独工作良好的旧的.exe) 我的解决方案在某些应用程序(如记事本)上运行得很好,但在目标VB6.exe上不起作用,VB6窗口从未在我的应用程序中托管,在尝试2或3次后,她将崩溃,仅此而已 这是我的WPF容器中的代码: 视图: <WindowsFormsHost Grid.Row="1" x:Name="windowsFormsHost1" Height="500" Width="650"

(这不是评论中解释的重新发布)

我的目的是在WPF中的容器中托管一个旧的.exe(由VB6生成的一个单独工作良好的旧的.exe)

我的解决方案在某些应用程序(如记事本)上运行得很好,但在目标VB6.exe上不起作用,VB6窗口从未在我的应用程序中托管,在尝试2或3次后,她将崩溃,仅此而已

这是我的WPF容器中的代码:

视图:

<WindowsFormsHost Grid.Row="1" x:Name="windowsFormsHost1" Height="500" Width="650" ></WindowsFormsHost>
我尝试了几个代码示例和不同的方法(比如从我的代码后面启动.exe,放置一个计时器,…),但我没能实现,我想我应该错过一个特殊性或其他东西

非常感谢你的帮助

编辑:
SetParent之后的MessageBox给了我信息,它可以用一致的值“本地化”我的目标vb6.exe。

可能重复的否我已经读过这篇文章,我的目的不同我有一个.exe(所以是一个普通的应用程序窗口),我想在我的wpf容器中托管这个窗口。我的代码适用于很多应用程序,但不是VB6生成的这个.exe(而且这个应用程序本身工作得很好)。可能是重复的。我已经读过这篇文章,我的目的是不同的。我有一个.exe(所以是一个普通的应用程序窗口),我想把这个窗口放在我的wpf容器中。我的代码可以使用很多应用程序,但不能使用VB6生成的这个.exe(仅此应用程序就可以很好地工作)。
        [DllImport("user32.dll", SetLastError = true)]
    internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        [DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("user32")]
    private static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent);


private void button1_Click(object sender, RoutedEventArgs e)
{
    try
    {
        Process p = Process.GetProcessById(Int32.Parse(ProcessNameTextBox.Text));

        // Get the main handle
        var appWin = p.MainWindowHandle;

        System.Windows.Forms.Panel _panel = new System.Windows.Forms.Panel();
        windowsFormsHost1.Child = _panel;

        // Put it into this form
        SetParent(appWin, windowsFormsHost1.Child.Handle);
        MessageBox.Show(appWin.ToString());

        // Remove border and whatnot

        SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);

        // Move the window to overlay it on this window
        MoveWindow(appWin, 0, 0, (int)this.Width, (int)this.Height, true);

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error");
    }
}