Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to render DirectX9 on my CLR customed control?

How to render DirectX9 on my CLR customed control?

Scheduled Pinned Locked Moved Managed C++/CLI
dotnetgraphicsgame-devdockertutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akira32
    wrote on last edited by
    #1

    My CLR project have many Split Containers, one Container has a customed user control. I want to Render a cylinder with DirectX9 on the user control. Could somebody tell how to get windows handle of user control or render with DirectX?

    A 1 Reply Last reply
    0
    • A akira32

      My CLR project have many Split Containers, one Container has a customed user control. I want to Render a cylinder with DirectX9 on the user control. Could somebody tell how to get windows handle of user control or render with DirectX?

      A Offline
      A Offline
      akira32
      wrote on last edited by
      #2

      reference: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/71bfe0b7-7609-4c8b-b106-f901e8f379b1[^] It depends on how your "customized user control" is implemented. However, it comes down to using the windows handle (HWND) and passing that to your DirectX device. If you're using MFC, everything derives from CWnd. You'll want to use CWnd::m_hWnd. If you're using Windows Forms with C++/CLI, everything will derive from Control, and you can use Control.Handle. -------------------------------------------------------------------------------- Reed Copsey, Jr. - http://reedcopsey.com

      A 1 Reply Last reply
      0
      • A akira32

        reference: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/71bfe0b7-7609-4c8b-b106-f901e8f379b1[^] It depends on how your "customized user control" is implemented. However, it comes down to using the windows handle (HWND) and passing that to your DirectX device. If you're using MFC, everything derives from CWnd. You'll want to use CWnd::m_hWnd. If you're using Windows Forms with C++/CLI, everything will derive from Control, and you can use Control.Handle. -------------------------------------------------------------------------------- Reed Copsey, Jr. - http://reedcopsey.com

        A Offline
        A Offline
        akira32
        wrote on last edited by
        #3

        That is my partial source code: public ref class PreviewView : public System::Windows::Forms::UserControl { LPDIRECT3DDEVICE9 d3ddev; private: void initD3D(HWND hHandle) { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface ZeroMemory(pd3dpp, sizeof(*pd3dpp)); // clear out the struct for use pd3dpp->Windowed = true; // program windowed, not fullscreen pd3dpp->SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames pd3dpp->hDeviceWindow = hHandle; // set the window to be used by Direct3D LPDIRECT3DDEVICE9 d3ddevTmp; // create a device class using this information and information from the d3dpp stuct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, pd3dpp, &d3ddevTmp); d3ddev=d3ddevTmp; } When I create device, I must use another variable d3ddevTmp to return the D3DDevice and then set to d3ddev member variable. If I use d3ddev to create device, it will appear the error message as below: Error 1 error C2664: 'IDirect3D9::CreateDevice' : cannot convert parameter 6 from 'cli::interior_ptr<Type>' to 'IDirect3DDevice9 **' d:\svn\......\PreviewView.h 121 Could somebody tell me how to solve this problem?

        L 1 Reply Last reply
        0
        • A akira32

          That is my partial source code: public ref class PreviewView : public System::Windows::Forms::UserControl { LPDIRECT3DDEVICE9 d3ddev; private: void initD3D(HWND hHandle) { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface ZeroMemory(pd3dpp, sizeof(*pd3dpp)); // clear out the struct for use pd3dpp->Windowed = true; // program windowed, not fullscreen pd3dpp->SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames pd3dpp->hDeviceWindow = hHandle; // set the window to be used by Direct3D LPDIRECT3DDEVICE9 d3ddevTmp; // create a device class using this information and information from the d3dpp stuct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, pd3dpp, &d3ddevTmp); d3ddev=d3ddevTmp; } When I create device, I must use another variable d3ddevTmp to return the D3DDevice and then set to d3ddev member variable. If I use d3ddev to create device, it will appear the error message as below: Error 1 error C2664: 'IDirect3D9::CreateDevice' : cannot convert parameter 6 from 'cli::interior_ptr<Type>' to 'IDirect3DDevice9 **' d:\svn\......\PreviewView.h 121 Could somebody tell me how to solve this problem?

          L Offline
          L Offline
          Lutoslaw
          wrote on last edited by
          #4

          You have to "pin" d3ddev which is currently controlled by the GC. That is, assign it to a pin_ptr<D3DDevice>.

          Greetings - Jacek

          A 1 Reply Last reply
          0
          • L Lutoslaw

            You have to "pin" d3ddev which is currently controlled by the GC. That is, assign it to a pin_ptr<D3DDevice>.

            Greetings - Jacek

            A Offline
            A Offline
            akira32
            wrote on last edited by
            #5

            Thanks. I has solved this problem.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups