Embed a DX-driven native window client area in WinForms

Started by
4 comments, last by neonic 10 years, 5 months ago

Hi,

I have looked on the mighty Internet, but there seems to be very little info on this specific topic. I have a native DX11-powered application which creates a Win32 render window, and I would like to make a WinForms C# app which starts the native app and embeds the client area of the DX11 window in a panel or something else which can be put in a window in the C# app. In other words, I would have the native app running as a child process of the C# app and the two would be running independently, but I would still like the mouse input given to the C# panel (or whatever) that the DX window is sitting in to be delivered to the native app.

Is this doable?

Thanks!

Advertisement

I'm not sure if it's possible to do it exactly the way you specified (with the child processes and all) but if you have control over your DX11 application, you could perhaps refactor it a bit so that you can pass it the handle of your WinForms control and have it create the main swapchain using that handle. Then DirectX will draw into that control's client area, and you would still have full control over any messages sent to the control (e.g. mouse move, etc..). You might have to mess around a bit with WM_PAINT to remove the annoying flicker, though.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Bacterius' suggestion is exactly what I did. I had an engine application that would run, and a C# based Editor application for composing the scenes. When you started the editor, it started a process (it wasn't a child process, was just running on its own, doing its own thing) with the -editor flag. This flag, in my engine, simply opened a socket & waited for a connection. The Editor application would connect, and send a pointer to a HWND of a control in the WinForm (I believe I used a Panel? can't remember thought). This would allow my engine to directly create the rendering context & such using the HWND of the C# control.

The rest of the editor application worked by sending messages across the network to the C++ engine.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.handle.aspx

Cool stuff, I think I am going to try what neonic suggested.

Thanks guys!

One more thing, did you need to specify any special flags or set up the panel in some particular way for the rendering to look correct?

I did not have time to implement what you suggested yet, but I remember having some problems when rendering DX content to a WinForms panel in the past. Something to do with various parts of the system wanting to do rendering in the control, so I am just asking before I go on writing something in a way that won't work.

It worked just fine for me. The only thing that was odd was you need to be sending information such as when the C# application moves or is resized, you need to inform the C++ engine that the viewport has changed.

Otherwise, it's like sliding a piece of paper with a hole cut in it over a monitor with 3D content on it (if that makes sense).

This topic is closed to new replies.

Advertisement