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

📄 gdicache.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 "GDICache.hpp"
#include "Common.hpp"


GDICache_t::GDICache_t()
{
}

GDICache_t::~GDICache_t()
{
    Reset();
}

void
GDICache_t::Reset(
    void
    )
{
    GdiCacheMap::iterator it = m_Cache.begin();
    while (it != m_Cache.end())
    {
        DeleteObject(it->second);
        it++;
    }

    if (!m_Cache.empty())
    {
        m_Cache.clear();
    }
}

HBITMAP
GDICache_t::LoadCachedBitmap(
    UINT BitmapId
    )
{
    GdiCacheMap::iterator it = m_Cache.find(BitmapId);

    // Return bitmap if already exists
    if (it != m_Cache.end())
    {
        return (HBITMAP)it->second;
    }

    // Otherwise load the bitmap
    HBITMAP Bitmap = LoadBitmap(
        GlobalData_t::s_ModuleInstance,
        MAKEINTRESOURCE(BitmapId)
        );
    if (Bitmap)
    {
        // Add it to the ID -> bitmap lookup
        m_Cache.insert(
            GdiCacheMap::value_type(
                BitmapId,
                Bitmap
                )
            );
    }

    return Bitmap;
}


HFONT
GDICache_t::LoadCachedFont(
    UINT FontId,
    UINT FontNameId,
    short Height,
    short Weight
    )
{
    GdiCacheMap::iterator itMap;

    // Return font if already exists
    itMap = m_Cache.find(FontId);
    if(itMap != m_Cache.end())
    {
        return (HFONT)(itMap->second);
    }

    // Otherwise create the necessary LOGFONT
    LOGFONT LogFont = {0};

    // Convert the height from point size to local units
    LogFont.lfHeight = - MulDiv(Height, GetDeviceCaps(NULL, LOGPIXELSY), 72);
    LogFont.lfWeight = Weight;

    StringCchCopyW(
        LogFont.lfFaceName,
        _countof(LogFont.lfFaceName),
        CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, FontNameId)
        );

    // Create the font
    HFONT Font = CreateFontIndirect(&LogFont);
    if (Font)
    {
        // Add it to the ID -> font lookup
        m_Cache.insert(
            GdiCacheMap::value_type(
                FontId,
                Font
                )
            );
    }

    return Font;
}

⌨️ 快捷键说明

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