当前位置: 首页>>代码示例>>C++>>正文


C++ ComPtr::SetParagraphAlignment方法代码示例

本文整理汇总了C++中microsoft::wrl::ComPtr::SetParagraphAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::SetParagraphAlignment方法的具体用法?C++ ComPtr::SetParagraphAlignment怎么用?C++ ComPtr::SetParagraphAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在microsoft::wrl::ComPtr的用法示例。


在下文中一共展示了ComPtr::SetParagraphAlignment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawDCompTileSurfaces

// Drawing tile content into tile surfaces using D2D batching
HRESULT Application::DrawDCompTileSurfaces()
{
    HRESULT hr = S_OK;

    // Defining tile colors
    D2D1_COLOR_F dcompTileSurfaceBackgroundColors [] =
    {
        D2D1::ColorF(D2D1::ColorF::LightBlue),
        D2D1::ColorF(D2D1::ColorF::BlueViolet),
        D2D1::ColorF(D2D1::ColorF::Blue),
        D2D1::ColorF(D2D1::ColorF::Cyan)
    };

    D2D1_COLOR_F dcompTileSurfaceForegroundColors [] =
    {
        D2D1::ColorF(D2D1::ColorF::Black),
        D2D1::ColorF(D2D1::ColorF::Black),
        D2D1::ColorF(D2D1::ColorF::Black),
        D2D1::ColorF(D2D1::ColorF::Black),
    };

    // Defining tile content
    const wchar_t *dcompTileSurfaceTexts [] =
    {
        L"1",
        L"2",
        L"3",
        L"4"
    };

    UINT dcompTileSurfaceWidth = 2 * _hWndClientWidth / 8;
    UINT dcompTileSurfaceHeight = 2 * _hWndClientHeight / 8;

    // Drawing content for all tile surfaces
    for (int i = 0; SUCCEEDED(hr) && i < 4; ++i)
    {
        Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2dDeviceContext;
        POINT updateOffset = { 0 };

        // Begin draw is using a D2D device context for D2D batching
        hr = _dcompTileSurfaces[i]->BeginDraw(nullptr, __uuidof(ID2D1DeviceContext) , reinterpret_cast<void **>(d2dDeviceContext.GetAddressOf()), &updateOffset);

        ShowMessageBoxIfFailed(hr, L"pDCompSurface->BeginDraw");

        if (SUCCEEDED(hr))
        {
            Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2dBackgroundBrush;

            if (SUCCEEDED(hr))
            {
                hr = d2dDeviceContext->CreateSolidColorBrush(dcompTileSurfaceBackgroundColors[i], &d2dBackgroundBrush);

                ShowMessageBoxIfFailed(hr, L"d2dDeviceContext->CreateSolidColorBrush");
            }

            Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2dForegroundBrush;

            if (SUCCEEDED(hr))
            {
                hr = d2dDeviceContext->CreateSolidColorBrush(dcompTileSurfaceForegroundColors[i], &d2dForegroundBrush);

                ShowMessageBoxIfFailed(hr, L"d2dDeviceContext->CreateSolidColorBrush");
            }

            Microsoft::WRL::ComPtr<IDWriteTextFormat> dwriteTextFormat;

            if (SUCCEEDED(hr))
            {
                hr = _dwriteFactory->CreateTextFormat(L"Verdana", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
                    DWRITE_FONT_STRETCH_NORMAL, 72.0f, L"en-us", &dwriteTextFormat);

                ShowMessageBoxIfFailed(hr, L"dwriteFactory->CreateTextFormat");
            }

            if (SUCCEEDED(hr))
            {
                hr = dwriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);

                ShowMessageBoxIfFailed(hr, L"dwriteTextFormat->SetTextAlignment");
            }

            if (SUCCEEDED(hr))
            {
                hr = dwriteTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);

                ShowMessageBoxIfFailed(hr, L"dwriteTextFormat->SetParagraphAlignment");
            }

            if (SUCCEEDED(hr))
            {
                D2D1_RECT_F dcompTileSurfaceRect = D2D1::RectF(
                    updateOffset.x + 0.0f * dcompTileSurfaceWidth,
                    updateOffset.y + 0.0f * dcompTileSurfaceHeight,
                    updateOffset.x + 1.0f * dcompTileSurfaceWidth,
                    updateOffset.y + 1.0f * dcompTileSurfaceHeight
                    );

                d2dDeviceContext->FillRectangle(
                    dcompTileSurfaceRect,
//.........这里部分代码省略.........
开发者ID:9578577,项目名称:Windows-classic-samples,代码行数:101,代码来源:Application.cpp

示例2: DrawDCompTextSurface

// Defining text properties and drawing text into the DComp text surface
HRESULT Application::DrawDCompTextSurface()
{
    HRESULT hr = S_OK;

    UINT dcompTextSurfaceWidth = 7 * _hWndClientWidth / 8;
    UINT dcompTextSurfaceHeight = 2 * _hWndClientHeight / 8;

    if (SUCCEEDED(hr))
    {
        Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2dDeviceContext;
        POINT updateOffset = { 0 };

        hr = _dcompTextSurface->BeginDraw(nullptr, __uuidof(ID2D1DeviceContext) , reinterpret_cast<void **>(d2dDeviceContext.GetAddressOf()), &updateOffset);

        ShowMessageBoxIfFailed(hr, L"_dcompTextSurface->BeginDraw");

        if (SUCCEEDED(hr))
        {
            Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2dBackgroundBrush;

            if (SUCCEEDED(hr))
            {
                hr = d2dDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &d2dBackgroundBrush);

                ShowMessageBoxIfFailed(hr, L"d2dDeviceContext->CreateSolidColorBrush");
            }

            Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2dForegroundBrush;

            if (SUCCEEDED(hr))
            {
                hr = d2dDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &d2dForegroundBrush);

                ShowMessageBoxIfFailed(hr, L"d2dDeviceContext->CreateSolidColorBrush");
            }

            Microsoft::WRL::ComPtr<IDWriteTextFormat> dwriteTextFormat;

            if (SUCCEEDED(hr))
            {
                hr = _dwriteFactory->CreateTextFormat(L"Verdana", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
                    DWRITE_FONT_STRETCH_NORMAL, 12.0f, L"en-us", &dwriteTextFormat);

                ShowMessageBoxIfFailed(hr, L"dwriteFactory->CreateTextFormat");
            }

            if (SUCCEEDED(hr))
            {
                hr = dwriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_JUSTIFIED);

                ShowMessageBoxIfFailed(hr, L"dwriteTextFormat->SetTextAlignment");
            }

            if (SUCCEEDED(hr))
            {
                hr = dwriteTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);

                ShowMessageBoxIfFailed(hr, L"dwriteTextFormat->SetParagraphAlignment");
            }

            if (SUCCEEDED(hr))
            {
                const wchar_t dcompTileSurfaceText [] = L"This sample demonstrates how to use DirectComposition to apply backface visibility and utilize performance optmization feature known as D2D Batching. Tiles 2 & 3 show backface visible while 1 & 4 show the backface hidden. \n\n"
                    L"Step 1. Tap or click any tile below \n"
                    L"Step 2. Reset by selecting background \n";

                D2D1_RECT_F dcompTextSurfaceRect = D2D1::RectF(
                    updateOffset.x + 0.0f * dcompTextSurfaceWidth,
                    updateOffset.y + 0.0f * dcompTextSurfaceHeight,
                    updateOffset.x + 1.0f * dcompTextSurfaceWidth,
                    updateOffset.y + 1.0f * dcompTextSurfaceHeight
                    );

                d2dDeviceContext->FillRectangle(
                    dcompTextSurfaceRect,
                    d2dBackgroundBrush.Get());

                d2dDeviceContext->DrawText(
                    dcompTileSurfaceText,
                    wcslen(dcompTileSurfaceText),
                    dwriteTextFormat.Get(),
                    &dcompTextSurfaceRect,
                    d2dForegroundBrush.Get());

                ShowMessageBoxIfFailed(hr, L"d2dDeviceContext->EndDraw");
            }
        }

        if (SUCCEEDED(hr))
        {
            hr = _dcompTextSurface->EndDraw();

            ShowMessageBoxIfFailed(hr, L"_dcompTextSurface->EndDraw");
        }
    }

    return hr;
}
开发者ID:9578577,项目名称:Windows-classic-samples,代码行数:99,代码来源:Application.cpp


注:本文中的microsoft::wrl::ComPtr::SetParagraphAlignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。