Creating multiple windows?

Hello there.

I’m writing an Emulator using Monogame for window creation, input and other things. I’ve done this before.
However, this time I’d like to use one window for my emulator’s output, and another window to display the debugger.

I can easily create a new window via something like this, on a button press for instance:

using (var otherWindow = new OtherWindow()) // derives from the Game class { otherWindow .Run(); }

However, when I do this, the main window does not run/update anymore. I can click it to focus it, but it is not intractable (no key events respond etc) and anything running on it pauses.

Is there any way to display two windows and keep both of them active at the same time?
Thank you

I think making an XNA control and putting it on a form would make this work. I assume you’re ok with being Windows only? If you need cross platform, you’ll need to write an implementation for each one, I don’t think there’s any built in support for this.

Anyway, I did some googling and it looks like the old XNA microsoft pages for this are no longer available. You might be able to find them on the wayback machine, or in other places from googling. There were a couple of topics but the first few hits weren’t quite what you need, I think?

I’ll let you do some digging on your own, but I’m pretty sure that’s the way you want to go. If you’re having troubles, let me know. I’m not entirely sure where, but somewhere on my harddrive I have an example of this haha.

I wrote the original code to do this in MG… lets see what i can remember…

Is there any way to display two windows and keep both of them active at the same time?

You just need to create a second GameWindow

var otherWindow = GameWindow.Create(myGame, sizeX, sizeY);

You then have one Game instance and two GameWindow instances.

You can use the otherWindow.Handle to get the HWND and do other things like place Winforms content or other things. If you want to display graphics on it you need to use the SwapChainRenderTarget class.

            var swapChain = new SwapChainRenderTarget(myGame.GraphicsDevice,
                                                  otherWindow.Handle,
                                                  otherWindow.ClientBounds.Width,
                                                  otherWindow.ClientBounds.Height,
                                                  false,
                                                  SurfaceFormat.Color,
                                                  DepthFormat.Depth24Stencil8,
                                                  1,
                                                  RenderTargetUsage.PlatformContents,
                                                  PresentInterval.Default);

Then in your main Game.Draw method you need to update the second window too…

            device.SetRenderTarget(swapChain);

            // your drawing code for the second window.

            swapChain.Present();

Note i don’t think we ever got the SwapChainRenderTarget working on anything other than Windows under DirectX… but that could be fixed if someone contributed some code.

Hope this helps you get started!

2 Likes