title: DirectX9 within Windows Forms
body: <p>I need to integrate a DirectX9 device in a C++ Windows Form - how do I do that? </p>
  
  <p>On the one hand I got my DirectX application....</p>
  
  <pre><code>HWND hWnd;
  WNDCLASSEX wc;
  
  ZeroMemory(&amp;wc, sizeof(WNDCLASSEX));
  
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = WindowProc;
  wc.hInstance = hInstance;
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.lpszClassName = "WindowClass";
  
  RegisterClassEx(&amp;wc);
  
  hWnd = CreateWindowEx(NULL, "WindowClass", "Engine",
                        WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                        NULL, NULL, hInstance, NULL);
  
  ShowWindow(hWnd, nCmdShow);
  
  m_D3D = Direct3DCreate9(D3D_SDK_VERSION);
  
  D3DPRESENT_PARAMETERS d3dpp;
  
  ZeroMemory(&amp;d3dpp, sizeof(d3dpp));
  d3dpp.Windowed = TRUE;
  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3dpp.hDeviceWindow = hWnd;
  d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
  d3dpp.BackBufferWidth = SCREEN_WIDTH;
  d3dpp.BackBufferHeight = SCREEN_HEIGHT;
  d3dpp.EnableAutoDepthStencil = TRUE;
  d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  
  // creates device
  m_D3D-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &amp;d3dpp, &amp;m_Device);
  </code></pre>
  
  <p>and on the other hand I got my Windows Form</p>
  
  <pre><code>Application::EnableVisualStyles();
  Application::SetCompatibleTextRenderingDefault(false); 
  Application::Run(gcnew Form1());
  </code></pre>
  
  <p>How do I merge this?</p>