Click here to Skip to main content
11,802,442 members (57,823 online)
Click here to Skip to main content
Add your own
alternative version

XHTMLTipOfTheDay - HTML Tip of the Day Dialog

, 14 Jun 2004 CPOL 52.4K 1.1K 43
XHTMLTipOfTheDay is a Tip of the Day dialog that displays HTML and has forward and back buttons.
// MemDC.h : header file

#ifndef MEMDC_H
#define MEMDC_H

// CMemDC - memory DC
// Author: Keith Rule
// Email:
// Copyright 1996-1997, Keith Rule
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
// History - 10/3/97 Fixed scrolling bug.
//                   Added print support.
//           25 feb 98 - fixed minor assertion bug
// This class implements a memory Device Context

class CMemDC : public CDC

    // constructor sets up the memory DC
    CMemDC(CDC* pDC) : CDC()
        ASSERT(pDC != NULL);

        m_pDC = pDC;
        m_pOldBitmap = NULL;
        m_bMemDC = !pDC->IsPrinting();
        if (m_bMemDC)    // Create a Memory DC
            m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
            m_pOldBitmap = SelectObject(&m_bitmap);
        else        // Make a copy of the relevent parts of the current DC for printing
            m_bPrinting = pDC->m_bPrinting;
            m_hDC       = pDC->m_hDC;
            m_hAttribDC = pDC->m_hAttribDC;
    // Destructor copies the contents of the mem DC to the original DC
        if (m_bMemDC) 
            // Copy the offscreen bitmap onto the screen.
            m_pDC->BitBlt(m_rect.left,, m_rect.Width(), m_rect.Height(),
                          this, m_rect.left,, SRCCOPY);

            //Swap back the original bitmap.
        } else {
            // All we need to do is replace the DC with an illegal value,
            // this keeps us from accidently deleting the handles associated with
            // the CDC that was passed to the constructor.
            m_hDC = m_hAttribDC = NULL;

    // Allow usage as a pointer
    CMemDC* operator->() {return this;}
    // Allow usage as a pointer
    operator CMemDC*() {return this;}

    CBitmap  m_bitmap;      // Offscreen bitmap
    CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
    CDC*     m_pDC;         // Saves CDC passed in constructor
    CRect    m_rect;        // Rectangle of drawing area.
    BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.


// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif //MEMDC_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 14 Jun 2004
Article Copyright 2004 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid