protandeous's picture

GLControl and WPF


I have peppered many forum threads with my issue of not seeing the GLControl in a NET40 application. The real issue is using it within a WPF window. WPF is backward compatible with Windows Forms, but needs an intermediary: WindowsFormsHost. I now have my custom class DOGG derived from GLControl. I also have a WPF window OGLwin which spawns it within its constructor:

    public partial class OGLwin : Window
        private DOGG ctl_dogg = null;
        public OGLwin()
            //Need a Windows Forms Host to house the pre-WPF control
            System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
            //create control
            ctl_dogg = new DOGG();
            //add control to host
            host.Child = ctl_dogg;
            //add host to XAML

Now everything is rendering great -- I just need to wire-up my events for keyboard / mouse / and timer for rendering

Hope this helps any other VS2010 WPF developers out there!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rtalan's picture

Has anyone made any progress in hosting an OpenTK.GameWindow in a WPF app?

For clarification, I'm talking about hosting the OpenTK.GameWindow in WPF , not an OpenTK.GLControl (notwithstanding the OpenTK.Examples project which uses a GLControl to create a 'slow' Game Window without the bells and whistles that come with a real OpenTK.GameWindow).

The HWNDHOST (the WindowsFormsHost is derived from HWNDHOST) needs the hwnd handle to the win32 window created by OpenTK.WinGLNative. But it is buried so deep and hidden away behind 'internal sealed' classes that it is impossible to get to.

Any ideas where OpenTK.WinGLNative might be modified to make this all possible?

Thanks for your time!

the Fiddler's picture

It is now possible to retrieve the window handle of a GameWindow:

GameWindow gw = new GameWindow();
IntPtr handle = gw.WindowInfo.Handle;

This configuration (hosting GameWindow inside WPF) has not been tested, it would be interesting to know if anyone has gotten this to work.