Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/walkthrough-creating-direct3d9-content-for-hosting-in-wpf.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

5.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Create Direct3D9 Content for Hosting 03/30/2017
cpp
WPF [WPF], creating Direct3D9 content
Direct3D9 [WPF interoperability], creating Direct3D9 content
286e98bc-1eaa-4b5e-923d-3490a9cca5fc

Walkthrough: Creating Direct3D9 Content for Hosting in WPF

This walkthrough shows how to create Direct3D9 content that is suitable for hosting in a Windows Presentation Foundation (WPF) application. For more information on hosting Direct3D9 content in WPF applications, see WPF and Direct3D9 Interoperation.

In this walkthrough, you perform the following tasks:

  • Create a Direct3D9 project.

  • Configure the Direct3D9 project for hosting in a WPF application.

When you are finished, you will have a DLL that contains Direct3D9 content for use in a WPF application.

Prerequisites

You need the following components to complete this walkthrough:

  • Visual Studio 2010.

  • DirectX SDK 9 or later.

Creating the Direct3D9 Project

The first step is to create and configure the Direct3D9 project.

To create the Direct3D9 project

  1. Create a new Win32 Project in C++ named D3DContent.

    The Win32 Application Wizard opens and displays the Welcome screen.

  2. Click Next.

    The Application Settings screen appears.

  3. In the Application type: section, select the DLL option.

  4. Click Finish.

    The D3DContent project is generated.

  5. In Solution Explorer, right-click the D3DContent project and select Properties.

    The D3DContent Property Pages dialog box opens.

  6. Select the C/C++ node.

  7. In the Additional Include Directories field, specify the location of the DirectX include folder. The default location for this folder is %ProgramFiles%\Microsoft DirectX SDK (version)\Include.

  8. Double-click the Linker node to expand it.

  9. In the Additional Library Directories field, specify the location of the DirectX libraries folder. The default location for this folder is %ProgramFiles%\Microsoft DirectX SDK (version)\Lib\x86.

  10. Select the Input node.

  11. In the Additional Dependencies field, add the d3d9.lib and d3dx9.lib files.

  12. In Solution Explorer, add a new module definition file (.def) named D3DContent.def to the project.

Creating the Direct3D9 Content

To get the best performance, your Direct3D9 content must use particular settings. The following code shows how to create a Direct3D9 surface that has the best performance characteristics. For more information, see Performance Considerations for Direct3D9 and WPF Interoperability.

To create the Direct3D9 content

  1. Using Solution Explorer, add three C++ classes to the project named the following.

    CRenderer (with virtual destructor)

    CRendererManager

    CTriangleRenderer

  2. Open Renderer.h in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#RendererH]

  3. Open Renderer.cpp in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#RendererCPP]

  4. Open RendererManager.h in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#RendererManagerH]

  5. Open RendererManager.cpp in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#RendererManagerCPP]

  6. Open TriangleRenderer.h in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#TriangleRendererH]

  7. Open TriangleRenderer.cpp in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#TriangleRendererCPP]

  8. Open stdafx.h in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#StdafxH]

  9. Open dllmain.cpp in the Code Editor and replace the automatically generated code with the following code.

    [!code-cppSystem.Windows.Interop.D3DImage#DllMain]

  10. Open D3DContent.def in the code editor.

  11. Replace the automatically generated code with the following code.

    LIBRARY "D3DContent"
    
    EXPORTS
    
    SetSize
    SetAlpha
    SetNumDesiredSamples
    SetAdapter
    
    GetBackBufferNoRef
    Render
    Destroy
    
  12. Build the project.

Next Steps

See also