All pastes #636046 Raw Edit

Something

public text v1 · immutable
#636046 ·published 2007-07-27 15:58 UTC
rendered paste body
using System;
using Gtk;
using Gdk;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;

namespace mwfingtk
{
	class MainClass
	{
		
		public static void Main (string[] args)
		{
			Gtk.Application.Init ();
			Gtk.Window gtkWindow = new Gtk.Window ("Title");
			gtkWindow.Add (new NativeContainer (InitializeMWF ().Handle));
			gtkWindow.Show ();
			
			Thread t = new Thread (Gtk.Application.Run); 
			t.Start ();
			while (!t.IsAlive) {};
		}
		
		private static Control InitializeMWF ()
		{
			Panel p = new Panel ();
			p.Visible = true;

			// run the MWF msg loop on a separate thread
			Thread t = new Thread (System.Windows.Forms.Application.Run); 
			t.Start ();
			while (!t.IsAlive) {};
			
			p.CreateControl ();
			while (!p.IsHandleCreated) {}
			
			return p;
		}
	}
	
	public class NativeContainer : Gtk.Container
	{
		private IntPtr _childHandle;
		
		public NativeContainer (IntPtr childHandle)
		{
			_childHandle = childHandle;
		}
		
		protected override void OnRealized ()
		{
			base.OnRealized ();
			Gdk.Window.ForeignNew ((uint) _childHandle).Reparent (this.GdkWindow, 0, 0);
		}
	}
}