Jump to content
  • Advertisement
Sign in to follow this  
Thorgrim

DirectX inside a form

This topic is 4496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!