Share via


DCompositionCreateDevice 函式 (dcomp.h)

建立可用來建立其他 Microsoft DirectComposition 物件的新裝置物件。

語法

HRESULT DCompositionCreateDevice(
  [in]  IDXGIDevice *dxgiDevice,
  [in]  REFIID      iid,
  [out] void        **dcompositionDevice
);

參數

[in] dxgiDevice

類型: IDXGIDevice*

用來建立 DirectComposition 表面物件的 DXGI 裝置。

[in] iid

類型: REFIID

要擷取之介面的識別碼。

[out] dcompositionDevice

類型: void**

接收新建立之裝置物件的介面指標。 指標是 iid 參數所指定的類型。 此參數不得為 Null。

傳回值

類型: HRESULT

如果函式成功,則會傳回S_OK。 否則,它會傳回 HRESULT 錯誤碼。 如需錯誤碼清單,請參閱 DirectComposition 錯誤碼

備註

裝置物件可作為所有其他 DirectComposition 物件的處理站。 它也會透過 IDCompositionDevice::Commit 方法控制交易式組合。

dxgiDevice 指定的 DXGI裝置是用來建立所有 DirectComposition 表面物件。 特別是, IDCompositionSurface::BeginDraw 方法會傳回屬於 dxgiDevice 參數所指定裝置的 DXGI 介面指標。

建立 DXGI 裝置時,開發人員必須指定 Microsoft Direct3D 資源的 Direct2D 互通性 D3D11_CREATE_DEVICE BGRA_SUPPORT或D3D10_CREATE_DEVICE_BGRA_SUPPORT 旗標。

iid參數必須是 __uuidof(IDCompositionDevice) ,而dcompositionDevice參數會收到IDCompositionDevice介面的指標。

範例

下列範例示範如何在初始化 DirectComposition 物件時建立裝置物件。

#include <dcomp.h>
#include <d3d11.h>

HRESULT InitializeDirectCompositionDevice(HWND hwndTarget, 
        ID3D11Device **ppD3D11Device, IDCompositionDevice **ppDevice,
        IDCompositionTarget **ppCompTarget)
{
    HRESULT hr = S_OK;
    D3D_FEATURE_LEVEL featureLevelSupported;
    IDXGIDevice *pDXGIDevice = nullptr;

    // Verify that the arguments are valid.
    if (hwndTarget == NULL || ppD3D11Device == nullptr || ppDevice == nullptr || 
                            ppCompTarget == nullptr)
    {
        return E_INVALIDARG;
    }

    // Create the D3D device object. Note that the 
    // D3D11_CREATE_DEVICE_BGRA_SUPPORT flag is needed for rendering 
    // on surfaces using Direct2D. 
    hr = D3D11CreateDevice(
        nullptr,
        D3D_DRIVER_TYPE_HARDWARE,
        NULL,
        D3D11_CREATE_DEVICE_BGRA_SUPPORT, // needed for rendering on surfaces using Direct2D
        NULL,
        0,
        D3D11_SDK_VERSION,
        ppD3D11Device,
        &featureLevelSupported,
        NULL);

    if (SUCCEEDED(hr))
    {
        // Create the DXGI device used to create bitmap surfaces.
        hr = (*ppD3D11Device)->QueryInterface(&pDXGIDevice);
    }

    if (SUCCEEDED(hr))
    {
        // Create the DirectComposition device object.
        hr = DCompositionCreateDevice(pDXGIDevice, __uuidof(IDCompositionDevice), 
                reinterpret_cast<void **>(ppDevice));
    }

    if (SUCCEEDED(hr))
    {
        // Bind the DirectComposition device to the target window.
        hr = (*ppDevice)->CreateTargetForHwnd(hwndTarget, TRUE, ppCompTarget);   
    }

    return hr;
}

需求

   
最低支援的用戶端 Windows 8 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2012 [僅限傳統型應用程式]
目標平台 Windows
標頭 dcomp.h
程式庫 Dcomp.lib
Dll Dcomp.dll

請參閱

函式