Click here to Skip to main content
13,893,974 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 24 Aug 2007
Licenced CPOL

The Ultimate Toolbox Graphics Classes

, 25 Aug 2007
Rate this:
Please Sign up or sign in to vote.
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.



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:

m_DIB.ResizeDIB(320, 200);
m_PeriDIB.Paint(pDC, CRect(0, 0, 320, 200), CRect(0, 0, 320, 200));


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.

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))

Image Viewer

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

The samples\graphics\ImageViewer sample in action.

Meta Files

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

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

    // 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"));
        if (! pDoc->m_MetaFile.PlayFile (pDC ) )
            AfxMessageBox (_T("Error in COXMetaFile::PlayFile"));
    return ;

Shaped Splash Window

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.


Initial CodeProject release August 2007.


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


About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created, 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.
Group type: Organisation

458 members

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid