> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameStreamingGetDisplayDetails

> XGameStreamingGetDisplayDetails

# XGameStreamingGetDisplayDetails

此 API 會傳回指定用戶端的顯示詳細資料。這可用來做出明智的決策，例如要以何種自訂外觀比例進行轉譯，或要使用何種解析度來啟用 DirectCapture。

## 語法

```cpp theme={null}
HRESULT XGameStreamingGetDisplayDetails(
        XGameStreamingClientId client,
        uint32_t maxSupportedPixels,
        float widestSupportedAspectRatio,
        float tallestSupportedAspectRatio,
        XGameStreamingDisplayDetails* displayDetails
)
```

### 參數

*client*   \_In\_\
類型：XGameStreamingClientId

要查詢的串流用戶端。

*maxSupportedPixels*   \_In\_\
類型：uint32\_t

遊戲支援的像素數目上限。

*widestSupportedAspectRatio*   \_In\_\
類型：float

遊戲支援的最寬外觀比例。這是使用支援的最寬解析度，以寬度 / 高度計算而得。

*tallestSupportedAspectRatio*   \_In\_\
類型：float

遊戲支援的最高外觀比例。這是使用支援的最高解析度，以寬度 / 高度計算而得。

*displayDetails*   \_Out\_\
類型：[XGameStreamingDisplayDetails\*](/zh-TW/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails)

串流用戶端的顯示詳細資料。

### 傳回值

類型：HRESULT

如果成功，則傳回 **S\_OK**；否則傳回錯誤碼。

#### 可能的錯誤

| 錯誤碼 | 錯誤值 | 錯誤原因 |
| - | - | - |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | XGameStreaming 執行階段尚未初始化。請先呼叫 XGameStreamingInitialize，再呼叫其他 API。 |
| E\_GAMESTREAMING\_CLIENT\_NOT\_CONNECTED | 0x89245401 | 指定的用戶端未連線。 |
| E\_GAMESTREAMING\_NO\_DATA | 0x89245402 | 要求的資料無法使用。資料稍後可能會可供使用。 |
| E\_INVALIDARG | 0x80070057 | 一或多個參數無效。`maxSupportedPixels` 必須大於 0。`widestSupportedAspectRatio` 必須等於或大於 16/9，且不得為無限大。`tallestSupportedAspectRatio` 必須等於或小於 16/9，且必須大於 0。 |

如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

`displayDetails` 中的資料可用來決定遊戲的各個層面，例如遊戲的轉譯解析度，以及要將重要資訊或 UI 放在何處，以確保其可供互動且不會被遮住。

`displayDetails` 結構中的 `preferredWidth` 和 `preferredHeight` 是根據串流用戶端上的實際顯示器、串流系統的限制，以及遊戲提供的參數 (`maxSupportedPixels`、`widestSupportedAspectRatio`、`tallestSupportedAspectRatio`) 而定。

請記住，資料在遊戲啟動時可能無法使用，在用戶端連線事件發生時也不一定可供使用，因此遊戲應使用事件或輪詢。

## 範例

```C++ theme={null}

#define DEFAULT_GAME_WIDTH 1920
#define DEFAULT_GAME_HEIGHT 1080

#define GAME_WIDEST_SUPPORTED_ASPECT_RATIO 21.5f / 9.0f
#define GAME_TALLEST_SUPPORTED_ASPECT_RATIO 16.0f / 10.0f

static uint32_t s_currentStreamWidth = DEFAULT_GAME_WIDTH;
static uint32_t s_currentStreamHeight = DEFAULT_GAME_HEIGHT;

// Option 1: Event driven. Note: be aware of potential threading issues when using the task queue.
void GameStreamingClientManager::OnConnectionStateChanged(XGameStreamingClientId client, XGameStreamingConnectionState connected)
{
    // Other connection work like registering or unregistering for the client properties change events.
    ...

    UpdateResolutionIfNeeded();
}

void GameStreamingClientManager::OnClientPropertiesChanged(
    XGameStreamingClientId client,
    uint32_t updatedPropertiesCount,
    XGameStreamingClientProperty* updatedProperties)
{
    for (uint32_t i = 0; i < updatedPropertiesCount; ++i)
    {
        switch (updatedProperties[i])
        {
        case XGameStreamingClientProperty::DisplayDetails:
        {
            UpdateResolutionIfNeeded();
            break;
        }

        default:
            // A characteristic we are not tracking - do nothing
            break;
        }
    }
}

// Option 2: Polling.

void Game::Update(DX::StepTimer const& timer)
{
    ...

    gameStreamingClientManager->UpdateResolutionIfNeeded();

    ...
}

void GameStreamingClientManager::UpdateResolutionIfNeeded()
{
    bool changeResolution = false;
    bool useDefaultResolution = true;

    // Only use custom resolution when there is only one streaming client connected.
    if (XGameStreamingGetClientCount() == 1)
    {
        XGameStreamingClientId client;
        uint32_t clientsUsed = 0;
        HRESULT hr = XGameStreamingGetClients(1, &client, &clientsUsed);
        if (SUCCEEDED(hr) && clientsUsed == 1)
        {
            XGameStreamingDisplayDetails displayDetails = {};
            hr = XGameStreamingGetDisplayDetails(client, DEFAULT_GAME_WIDTH * DEFAULT_GAME_HEIGHT, GAME_WIDEST_SUPPORTED_ASPECT_RATIO, GAME_TALLEST_SUPPORTED_ASPECT_RATIO, &displayDetails);

            if (SUCCEEDED(hr))
            {
                useDefaultResolution = false;

                // Assuming the game supports all resolutions, use the stream resolution to the preferred dimensions as provided.
                if (s_currentStreamWidth != displayDetails.preferredWidth || s_currentStreamHeight != displayDetails.preferredHeight)
                {
                    changeResolution = true;
                    s_currentStreamWidth = displayDetails.preferredWidth;
                    s_currentStreamHeight = displayDetails.preferredHeight;
                }
            }
            else
            {
                LogFormat(L"XGameStreamingGetDisplayDetails failed %x", hr);
            }
        }
        else
        {
            LogFormat(L"XGameStreamingGetClients failed hr=%x clientsUsed=%d", hr, clientsUsed);
        }
    }

    if (useDefaultResolution)
    {
        if (s_currentStreamWidth != DEFAULT_GAME_WIDTH || s_currentStreamHeight != DEFAULT_GAME_HEIGHT)
        {
            changeResolution = true;
            s_currentStreamWidth = DEFAULT_GAME_WIDTH;
            s_currentStreamHeight = DEFAULT_GAME_HEIGHT;
        }
    }

    if (changeResolution)
    {
        // Update the stream to the new resolution.
        HRESULT hr = XGameStreamingSetResolution(s_currentStreamWidth, s_currentStreamHeight);
        if (SUCCEEDED(hr))
        {
            // Update the game to render at the new resolution.
        }
        else
        {
            LogFormat(L"XGameStreamingSetResolution failed %x", hr);
        }
    }
}

```

## 需求

**標頭：** xgamestreaming.h\
**程式庫：** xgameruntime.lib\
**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XGameStreaming](/zh-TW/reference/system/xgamestreaming/xgamestreaming_members)

[XGameStreamingDisplayDetails](/zh-TW/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails)

[XGameStreamingRegisterClientPropertiesChanged](/zh-TW/reference/system/xgamestreaming/functions/xgamestreamingregisterclientpropertieschanged)

[XGameStreamingSetResolution](/zh-TW/reference/system/xgamestreaming/functions/xgamestreamingsetresolution)

[自訂解析度概觀](/zh-TW/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)


## Related topics

- [XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails.md)
- [XGameStreamingDisplayDetails](/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails.md)
