Sign in to follow this  
acron86

Managed DX in MDI Forms.

Recommended Posts

acron86    122
I'm struggling with a bit of code here... I'm basically writing a GUI editor and decided to use Managed DirectX as it handles Sprites quite nicely. What I'm struggling with is getting the device created in an MDI window. My forms are wrapped up so that they all, by default, becaome MDI children of the main form, but when I try and create my form with DX, it bombs. However, I can fixing by just removing the MDI relationship: this.MdiParent = null; Are there some extra settings I need to toggle in order to get the device working as intended? The code is: try { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.BackBufferFormat = Format.Unknown; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; // Store the default adapter int adapterOrdinal = Manager.Adapters.Default.Adapter; CreateFlags flags = CreateFlags.SoftwareVertexProcessing; // Check to see if we can use a pure hardware device Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware); // Do we support hardware vertex processing? if (caps.DeviceCaps.SupportsHardwareTransformAndLight) // Replace the software vertex processing flags = CreateFlags.HardwareVertexProcessing; // Do we support a pure device? if (caps.DeviceCaps.SupportsPureDevice) flags |= CreateFlags.PureDevice; device = new Device(0, DeviceType.Hardware, this, flags, presentParams); // <<<<<<<<<<<<<<< CRASHING HERE. device.DeviceReset += new System.EventHandler(this.OnResetDevice); OnResetDevice(device, null); SetUpViews(); // Fonts InitialiseFonts(); } catch (DirectXException) { // Catch any errors and return a failure } And the error I'm getting is "Error creating window handle.". Thanks for your help!

Share this post


Link to post
Share on other sites
remigius    1172
Quote:
it bombs


That's probably the most descriptive error message I've seen in a while [smile]

Seriously though, the "Error creating window handle" is also a bit vague. If the error is coming from DirectX, you can probably get a more meaningful message by enabling the debug runtimes (see below). To actually see the debug output, you'll either need the debugview tool or enabled unmanaged debugging in your project's property sheet, on the debug tab (not available in Express editions).

As a random shot in the dark, I think the MDI parent relationship makes D3D resolve to the main parent window handle for the device creation. Going from this post it seems the device needs to be set up on the parent window and children require an additional swap chain.

Share this post


Link to post
Share on other sites
acron86    122
I tried unmanaged debugging and just got 'E_FAIL'.

Anyway, i've managed to get working. Not sure if this is a fudge or not but all i've done is Fill-Dock'd a PictureBox on the form and rendered to that. Seems to do the trick ;)

Share this post


Link to post
Share on other sites
juergen1969    140
Hi acron86,
Microsft's managed directx is a bit buggy.
I tried to use SlimDx in my project and it works better. I had some problems with a docking solution to switch between document and float style. It crashed many times. So I did it with SlimDx and it works.
If you have the alternative, try it out.

Jürgen

Share this post


Link to post
Share on other sites
acron86    122
I appreciate the info juergen1969.

I've done a few MDX things before and it's always a bit of a headache. I'll have a look at SlimDX, as I've not heard of it before.

Cheers :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this