GameChatOverlay 类

定义

表示游戏聊天覆盖。

public ref class GameChatOverlay sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class GameChatOverlay final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class GameChatOverlay
Public NotInheritable Class GameChatOverlay
继承
Object Platform::Object IInspectable GameChatOverlay
属性

Windows 要求

设备系列
Windows 10 Creators Update (在 10.0.15063.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v4.0 中引入)

示例

此示例演示如何设置游戏聊天并向其添加短信。

#include <winrt/Windows.Gaming.UI.h>
using namespace winrt;
using namespace Windows::Gaming::UI;
...
GameChatOverlay m_gameChatOverlay{nullptr};
...
void ChatSample::SetUpGameChat(GameChatOverlayPosition position)
{
    // Get the default game chat overlay object. Platforms that don't support
    // it will return null.
    m_gameChatOverlay = GameChatOverlay::GetDefault();

    if (m_gameChatOverlay)
    {
        // Position the overlay in the given position.
        m_gameChatOverlay.DesiredPosition(position);
    }
}

// This method typically would be wired to a text entry box in order to send
// text messages.
void ChatSample::SendTextMessage(std::wstring gamertag, std::wstring message)
{
    if (m_gameChatOverlay)
    {
        // Render the text in the overlay.
        m_gameChatOverlay.AddMessage(
            gamertag,
            message,
            GameChatMessageOrigin::Text);
    }
    else
    {
        // The game should render the outgoing message in its own UI.
    }
}
void ChatSample::SetUpGameChat(GameChatOverlayPosition position)
{
    // Get the default game chat overlay object. Platforms that don't support
    // it will return null.
    m_gameChatOverlay = GameChatOverlay::GetDefault();

    if (m_gameChatOverlay)
    {
        // Position the overlay in the given position.
        m_gameChatOverlay->DesiredPosition = position;
    }
}

// This method typically would be wired to a text entry box in order to send
// text messages.
void ChatSample::SendTextMessage(String^ gamertag, String^ message) 
{
    if (m_gameChatOverlay)
    {
        // Render the text in the overlay.
        m_gameChatOverlay->AddMessage(
            gamertag, 
            message, 
            GameChatMessageOrigin::Text);
    }
    else 
    { 
        // The game should render the outgoing message in its own UI.
    } 
}

注解

此类提供用于获取默认游戏聊天覆盖实例、设置覆盖层的所需位置以及向其添加消息的方法。

属性

DesiredPosition

游戏聊天覆盖的所需位置。

方法

AddMessage(String, String, GameChatMessageOrigin)

在游戏聊天覆盖中呈现消息。

GetDefault()

获取默认的游戏聊天覆盖实例。

适用于

另请参阅