2010年2月10日 星期三

CuFont



//


class CuFont  
{
    HDC m_hDC;
    HFONT m_hFont;

public:
    void Release();
    void SetFontSize(int iFontSize);
    CuFont(HDC hDC);
    virtual ~CuFont();


private:
    CuFont(){}

};


//


CuFont::CuFont(HDC hDC):
m_hFont(NULL)
{
    m_hDC = hDC;
}

CuFont::~CuFont()
{

    if( m_hDC )
        Release();
}

void CuFont::SetFontSize(int iFontSize)
{
    if( !m_hDC )
        return;

    HFONT hFontCreated = NULL;
    HFONT hFont = (HFONT) GetStockObject(SYSTEM_FONT);

    hFontCreated = CuFontManager::Instance()->GetFontHandle(hFont, iFontSize);

    m_hFont = (HFONT)::SelectObject(m_hDC, hFontCreated);

    DeleteObject(hFont);

}

void CuFont::Release()
{
    if( m_hDC && m_hFont )
    {
        HFONT hFontCreated = (HFONT)::SelectObject(m_hDC, m_hFont);
    }

    m_hDC = NULL;
}

沒有留言:

張貼留言