刚开始用VC,发现到处都是问题,以前用vb太多了。
现在攒了3千多分,现在拼命问问题了!!最常见的CMemDC:
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email:  [email protected]
// 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 Contextclass CMemDC : public CDC
{
public:    // 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
        {
            pDC->GetClipBox(&m_rect);
            CreateCompatibleDC(pDC);
            m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
            m_pOldBitmap = SelectObject(&m_bitmap);
            SetWindowOrg(m_rect.left, m_rect.top);
        }
        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
    ~CMemDC()
    {
        if (m_bMemDC) 
        {    
            // Copy the offscreen bitmap onto the screen.
            m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
                          this, m_rect.left, m_rect.top, SRCCOPY);            //Swap back the original bitmap.
            SelectObject(m_pOldBitmap);
        } 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;}private:
    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.
};#endif我有几个问题不解1.构造函数中的CMemDC(CDC* pDC):CDC()
那个CDC()干什么用的,我查了csdn,发现CDC()不返回任何数据啊2.operator CMemDC*() {return this;}
是什么意思,是操作符重载?如果是的话,请帮忙详细讲讲啊。。

解决方案 »

  1.   

    1.调用基类CDC的构造函数
    2.用于从CMemDC到CMemDC*的隐式转换。
      

  2.   

    1。CMemDc继承至CDC,初始化时,要调用CDC的构造函数
    2。同上!
      

  3.   

    初始化时,如何调用cdc的构造函数??
      

  4.   

    你创建了对象,比如CDC dc,首先调用的就是构造函数,你可以在构造函数里加段代码试试cout<<"this is CDC constructor"<<endl;
    建议看看c++的基础书籍,呵呵,我以前也是用vb的 :)
      

  5.   

    当我们需要一个类对象而又不知道初始值应该是什么的时候在程序中这种情况也是有
    可能的如dat04 或许这些值只能在后面才可以确定但是我们仍需要提供一些初始值
    或者只是表明现在还没有提供初始值在某些意义上来说有时候需要初始化一个类对象表
    明它还没有被初始化多数类都提供了一个特殊的缺省构造函数default constructor 它
    不需要指定初始值典型情况下如果类对象是由缺省构造函数初始化的则我们可以认为
    它还没有被初始化.
    选自primer 566页,唉,你们都没有懂我的意思,不管怎样,多谢了!