Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me, how to open External exe application in a WPF Window. Thanks...

Below is the code...sample right now..i am using.. let me know what i need to modify in the code below..to work for external exe to launch in WPF window. This is opening application in separately not in WPF Window.

C#
namespace WpfApplication_Blend
{
/// 
/// Interaction logic for Window1.xaml
/// 
public partial class Window1 : Window
{
public IntPtr MainWindowHandle { get; set; }
 

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

//[DllImport("user32.dll", SetLastError = true)]
//private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 
public Window1()
{
InitializeComponent();
 
try
{
//External exe inside WPF Window 
System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();
 
WindowsFormsHost windowsFormsHost1 = new WindowsFormsHost();
 
windowsFormsHost1.Child = _pnlSched;
 
_Grid.Children.Add(windowsFormsHost1);
 
ProcessStartInfo psi = new ProcessStartInfo(@"C:\Program Files\Atwin\Atwin2k2.exe");
 
psi.WindowStyle = ProcessWindowStyle.Normal;
 
Process PR = Process.Start(psi);
 
PR.WaitForInputIdle(); // true if the associated process has reached an idle state.
SetParent(PR.MainWindowHandle, _pnlSched.Handle); // loading exe to the wpf window.
 
}
catch (Exception ex)
{ 
//Nothing...
}
}
 

 
}
Posted
Updated 27-May-12 8:42am
v2
Comments
Sergey Alexandrovich Kryukov 27-May-12 22:09pm    
Why doing such dirty and bad things at all?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900