⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transparenttextbox.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "TransparentTextBox.hpp"
#include "PaintHelper.hpp"
#include "Common.hpp"


static const DWORD sc_SupportedDrawTextFlags = (
    DT_TOP |
    DT_LEFT |
    DT_CENTER |
    DT_RIGHT |
    DT_VCENTER |
    DT_BOTTOM |
    DT_WORDBREAK |
    DT_SINGLELINE |
    DT_EXPANDTABS |
    DT_NOPREFIX |
    DT_END_ELLIPSIS
    );

/*------------------------------------------------------------------------------
    TransparentTextBoxImpl_t::ControlWindowProc

    Handle messages
------------------------------------------------------------------------------*/
LRESULT
TransparentTextBoxImpl_t::ControlWindowProc(
    UINT Message, 
    WPARAM wParam, 
    LPARAM lParam, 
    bool & Handled
    )
{
    Handled = true;
    LRESULT Result;

    switch (Message)
    {
    case WM_CREATE:
        m_Font = NULL;
        return 0;

    case WM_ERASEBKGND:
        return 1;

    case WM_PAINT:
        return OnPaint();

    case WM_SETFONT:
        m_Font = reinterpret_cast<HFONT>(wParam);
        return 0;

    case WM_SETTEXT:
        Result = DefWindowProc(Message, wParam, lParam);
        InvalidateRect(m_hwnd, NULL, TRUE);
        return Result;

    default:
        Handled = false;
        return 0;
    }
}

/*------------------------------------------------------------------------------
    TransparentTextBoxImpl_t::OnPaint
    
    Handle WM_PAINT for this control
------------------------------------------------------------------------------*/
LRESULT 
TransparentTextBoxImpl_t::OnPaint(
    void
    )
{
    PaintHelper_t paint;
    HRESULT hr;

    //start the paint process
    hr = paint.Begin(m_hwnd);
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return 0;
    }

    WCHAR TextBuffer[MAX_PATH];

    RECT ClientRect = {0};
    GetClientRect(m_hwnd, &ClientRect);

    //have our parent draw its background into 
    //the paint DC
    if (! ForwardEraseBackground(paint))
    {
        ASSERT(FALSE);
        goto exit;
    }

    //now draw our text 
    if (GetWindowText(m_hwnd, TextBuffer, _countof(TextBuffer)) > 0)
    {
        paint.SetTextColor(PHGetColor(phcDisplayItemSelectedBackgroundColor));
        paint.SetBkMode(TRANSPARENT);

        if (m_Font == NULL)
        {
            m_Font = PHGetFont(phfStandardText);
        }
        paint.SetFont(m_Font);

        // set DrawText flags
        DWORD Style = GetWindowLong(m_hwnd, GWL_STYLE);
        DWORD DrawTextFlags = (Style & sc_SupportedDrawTextFlags);

        if (0 == DrawTextFlags)
        {
            // default to left alignment with no prefix, word wrap and end ellipsis
            DrawTextFlags = DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_END_ELLIPSIS;
        }

        hr = paint.DrawText(
            TextBuffer, 
            -1, 
            &ClientRect, 
            DrawTextFlags
            );
        ASSERT(SUCCEEDED(hr));
    }
    
exit:    
    paint.End();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -