WPF

Just a simple question, might be a stupid one… but is it possible to use WPF with OF? Probably for building nice UIs? But I know that WPF is more or less used with C# bindings. So is it possible?

1 Like

It’s possible.
You can compile OF as Dll. Make something like that :

#define EXTERN __declspec(dllexport)
extern "C"
{
  EXTERN void* createWindow()
  {
    ofGLWindowSettings settings;   
    settings.setGLVersion(2, 1);
    ofCreateWindow(settings);
    HWND hwnd = WindowFromDC(wglGetCurrentDC());
    return hwnd;
  }
}

#define EXTERN __declspec(dllexport)
  extern "C"
  {
    EXTERN void startRenderer()
    {
      ofRunApp(new ofApp());
    }
}

Than you can get it in your WPF App (of course you can just take an *.EXE and host it  but the communication will be complicate  )

On the WPF side:

 [DllImport("PointCloud.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern IntPtr createWindow();

 [DllImport("PointCloud.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern void startRenderer();

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

IntPtr _appWin = createWindow();
var helper = new WindowInteropHelper(Window.GetWindow(this.AppContainer));
SetParent(_appWin, helper.Handle);

//and than
startRenderer();

So except this changes it’s a same way, that was showing here

1 Like