Sign in to follow this  
Thorgrim

DirectX inside a form

Recommended Posts

Ok, so I am trying to create a DirectX display within a windows Form object in C++. The problem is that I am having some issues initialising it. Although the code compiles fine, I get the error: D3DERR_INVALIDCALL when creating the D3D device. Here is the line giving the error (called when creating the window):

	try
    {
		PresentParameters^ presentParams = gcnew PresentParameters();

		device = 
			gcnew Device(
			0,
			DeviceType::Hardware, 
			render->Handle, 
			CreateFlags::SoftwareVertexProcessing, 
			gcnew cli::array<PresentParameters^> {presentParams});
	}
	catch (Microsoft::DirectX::DirectXException^ e)
    { 
		MessageBox::Show(e->ToString(), 
		    "Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
		return; 
    }

render is a pannel (though using the form itself doesn't seem to help) and device is of type Device ^. I have been googling around, but almost all evamples are for anything but C++... If anyone has an example of displaying a DirectX window within a form, or what is wrong with my code, then please let me know, thanks :)

Share this post


Link to post
Share on other sites
You forgot to set some default variables. Although the window width and height and all the other variables aren't needed it's generally good practise to set them. What you forgot was the SwapChain effect.

pparams.SwapEffect = SwapEffect.Discard; //or whatever.

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
Thanks a lot Armadon!

I had tried setting a few properties, but that was one I hadn't tried. Seems to work perfectly now :)

Just need to figure out a nice way to thread it so I can use buttons etc at the same time...

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