【问题标题】:Running an exe file in a new Itemtab in wpf application在 wpf 应用程序的新 Itemtab 中运行 exe 文件
【发布时间】:2013-09-25 09:10:06
【问题描述】:

我是开发 Wpf 的初学者,我需要知道如何在 TabControl 控件中的新 TabItem 中运行 .exe 应用程序。 我做了这个sn-p:

 private void MenuItem_Click_6(object sender, RoutedEventArgs e) { 
    TabItem nPage = new TabItem();
    nPage.Header = "nouveau";
    TabPage.Items.Add(nPage);
    ProcessStartInfo pInfo = new ProcessStartInfo("Multi-langue.exe");
    pInfo.WorkingDirectory = @"C:\Multi-langue\Multi-langue\bin\Debug";
    Process p = Process.Start(pInfo);
    }

新应用程序正在运行,但不在新的TabItem 中。

那么如何修改我的 sn-p 以集成在第一个应用程序中启动的第二个应用程序的显示?

【问题讨论】:

标签: c# .net wpf process


【解决方案1】:

我找到了这个解决方案,效果很好

 public IntPtr MainWindowHandle { get; set; }
          [DllImport("user32.dll", SetLastError = true)]
        private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

  private void MenuItem_Click_6(object sender, RoutedEventArgs e) { 

        TabItem nPage = new TabItem();
        WindowsFormsHost host = new WindowsFormsHost();
        System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
        host.Child = p;
        nPage.Header = "nouveau";
        nPage.Content = host;
        TabPage.Items.Add(nPage);
        Process proc = Process.Start(
   new ProcessStartInfo()
   {
       FileName = @"C:\Multi-langue\Multi-langue\bin\Debug\Multi-langue.exe",

       WindowStyle = ProcessWindowStyle.Normal
   });
        Thread.Sleep(1000);
        SetParent(proc.MainWindowHandle, p.Handle);

    }

【讨论】:

  • 不错!我建议把 proc.WaitForInputIdle();而不是 Thread.Sleep(1000) 因为它是等待 proc 的主 UI 线程准备好接收 SetParent 消息的更快方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多