Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC
Article

The Ultimate Toolbox Graphics Classes

Rate me:
Please Sign up or sign in to vote.
4.67/5 (5 votes)
25 Aug 2007CPOL2 min read 46.2K   298   22  
Ultimate Toolbox classes that help with DIBs, MetaFiles, and more.

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Contents

Introduction

The Ultimate Toolbox contains several classes that enable the integration of graphic-based routines in your MFC based application.

Device Independent Bitmaps

COXDIB is an MFC extension encapsulating DIB operations. It includes functionality for reading/writing BMP and JPG files, conversion, palette extraction, resizing, rotation (at 90°increments), dithering, and drawing. Many of the Ultimate Toolbox classes make use of this class for graphics file rendering.

As an example, consider the rendering of a large 24 bit per pixel bitmap in a small area on a 256 color display. The best approach is to resize, dither, then render the resulting dib:

C++
...
m_DIB.Read("c:\some.bmp");
m_DIB.ResizeDIB(320, 200);
m_DIB.HalfToneDitherDIB();
...
m_PeriDIB.Paint(pDC, CRect(0, 0, 320, 200), CRect(0, 0, 320, 200));
...

Graphics

COXGraphics class was designed in order to provide advanced graphics routines for programmers. It is currently used internally in the COXRoundedButton class to render the button.

Image 1

C++
void COXRoundedButton::DrawButtonBackground(CDC* pDC, CRect buttonRect, 
    UINT nState, CPalette* pPalette/*=NULL*/)
{
    // back color, may be used as transparent color

    COLORREF BackColor=m_clrBk;

    CSize szRadius=CalcSphereRadius();

    COXGraphics graphics;

    if (!(IsChecked() || (nState & ODS_SELECTED) == ODS_SELECTED))
    {
        graphics.DrawRoundedButton(pDC,buttonRect.left,buttonRect.top,
            buttonRect.Width(),buttonRect.Height(),
            szRadius.cx,szRadius.cy,pPalette,
            m_clrButton,m_clrLight,m_fThetta, 
            m_fPhi,m_fLightIntensityCoef,
            m_nPhong,m_fMirror,m_fDiffuse,
            m_fAmbient,BackColor);
    }
    else
    {
        graphics.DrawRoundedButton(pDC,buttonRect.left,buttonRect.top,
            buttonRect.Width(),buttonRect.Height(),
            szRadius.cx,szRadius.cy+(szRadius.cx-szRadius.cy)/3,pPalette,
            m_clrButton,m_clrLight,m_fThetta, 
            m_fPhi+180,m_fLightIntensityCoef,
            m_nPhong,0,m_fDiffuse,
            m_fAmbient,BackColor);
    }
}

Image Viewer

The COXImageViewer class is a COXScrollWnd based class which is designed to display DIB (bitmap) and (optionally) JPEG images.

Image 2
The samples\graphics\ImageViewer sample in action.

Meta Files

COXMetaFile supports Windows 3.x, Aldus header and enhanced metafiles (*.wmf and *.emf).

Image 3
A metafile as displayed in the samples/graphics/metafile example.
C++
void CMetaFileView::OnDraw(CDC* pDC)
{
    CMetaFileDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    // TODO: add draw code for native data here

    CRect rectClient;
    GetClientRect( &rectClient);
    if (m_bMaintainRatio)
    {    
        if (! pDoc->m_MetaFile.PlayFile (pDC, &rectClient) )
            AfxMessageBox (_T("Error in COXMetaFile::PlayFile"));
    }
    else
    {    
        if (! pDoc->m_MetaFile.PlayFile (pDC ) )
            AfxMessageBox (_T("Error in COXMetaFile::PlayFile"));
    }
    return ;
}

Shaped Splash Window

Image 4

COXSplashWnd and COXSplashWndDIB allow for quick and easy implementation of customizable splash windows.

The LoadBitmap method of COXSplashWndDib can specify a border color (default is 0xFF000000) that will be made transparent, giving the appearance of a shaped window. Each outer pixel in this color will be made invisible.

COXSplashWnd can be seen in action in the samples\graphics\Splash example.

History

Initial CodeProject release August 2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions

 
-- There are no messages in this forum --