Hi,
hm, does it really open a "new" Window for Chrome and VLC Player?
I'm also hosting WindowsForms with Espen Harlinns Solution (SetParent), tried it with VLC and Chrome and it gets emmbedded in window or wpf page successfully.
I read the interesting links from SAKryukov and Harlinn and now I don't know if it's because of the missing rendering that I'm not able to resize the window at the moment.
Don't tried it with serveral WindowsFormsHost as in Tabifier Article.
However, I was wondering why it's not working for you to embedd exactly the applications you wrote.
I embedded it this way:
XAML
<TabItem Name="tab1" Header="Tab 1" Foreground="White" FontWeight="Bold" FontSize="20">
<my:Window_Host_Helper x:Name="host"></my:Window_Host_Helper>
</TabItem>
public class Window_Host_Helper : System.Windows.Controls.ContentControl
{
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
const UInt32 SWP_FRAMECHANGED = 0x0020;
static readonly int GWL_STYLE = (-16);
public const uint WS_CAPTION = 0x00C00000;
public const uint WS_THICKFRAME = 0x00040000;
public const uint WS_CLIPCHILDREN = 0x02000000;
public const uint WS_OVERLAPPED = 0x00000000;
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
private WindowsFormsHost host = new WindowsFormsHost();
private System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel();
private IntPtr windowHandle;
public System.Diagnostics.Process Process
{
set
{
try
{
value.Start();
if (!value.WaitForInputIdle(3000))
{
throw new ArgumentException();
}
System.Threading.Thread.Sleep(1000);
this.windowHandle = value.MainWindowHandle;
int dwStyle = GetWindowLong(this.windowHandle, GWL_STYLE);
SetWindowLong(this.windowHandle, GWL_STYLE, new IntPtr(dwStyle &
~WS_CAPTION & ~WS_THICKFRAME));
SetWindowPos(this.windowHandle, IntPtr.Zero, 0, 0, Convert.ToInt32(Math.Floor(this.ActualWidth)), Convert.ToInt32(Math.Floor(this.ActualHeight)), SWP_FRAMECHANGED);
SetParent(this.windowHandle, panel.Handle);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
}
public Window_Host_Helper()
{
this.Content = host;
this.panel.CreateControl();
host.Child = this.panel;
}
protected override void OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
}
protected override System.Windows.Size ArrangeOverride(System.Windows.Size arrangeBounds)
{
base.ArrangeOverride(arrangeBounds);
SetWindowPos(this.windowHandle, IntPtr.Zero, 0, 0, Convert.ToInt32(Math.Floor(arrangeBounds.Width)), Convert.ToInt32(Math.Floor(arrangeBounds.Height)), 0);
return arrangeBounds;
}
protected override void OnContentChanged(object oldContent, object newContent)
{
this.Content = this.host;
}
}
Usage:
Process p = new Process();
p.StartInfo = new ProcessStartInfo("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe");
host.Process = p;
Best Regards