MEMDC.H
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:12k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- #if !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)
- #define AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- // MemDC.h : header file
- //
- //////////////////////////////////////////////////
- // CMemDC - memory DC
- //
- // Author: Keith Rule
- // Email: keithr@europa.com
- // 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 CMemDCBase : public CDC
- {
- public:
- // constructor sets up the memory DC
- CMemDCBase(CDC* pDC) : CDC()
- {
- // ASSERT(pDC != NULL);
- m_pDC = pDC;
- m_pOldBitmap = NULL;
- m_bMemDC = !pDC->IsPrinting();
- }
- // Destructor copies the contents of the mem DC to the original DC
- ~CMemDCBase()
- {
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- }
- // Allow usage as a pointer
- CMemDCBase* operator->() {return this;}
- // Allow usage as a pointer
- operator CMemDCBase*() {return this;}
- private:
- protected:
- 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.
- };
- /*class CMemDC : public CMemDCBase
- {
- public:
- // constructor sets up the memory DC
- CMemDC(CDC* pDC) : CMemDCBase(pDC)
- {
- 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;
- }
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- DeleteDC();
- }
- // Allow usage as a pointer
- CMemDC* operator->() {return this;}
- // Allow usage as a pointer
- operator CMemDC*() {return this;}
- private:
- protected:
- };
- */
- class 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.
- };
- /*
- class CNCMemDC : public CDC
- {
- public:
- // constructor sets up the memory DC
- void Resize(CDC* pDC,RECT rcAll,RECT rc)
- {
- m_rect = rcAll;
- m_rc = rc;
- {
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- m_bitmap.CreateCompatibleBitmap(pDC, rc.right-rc.left,rc.bottom-rc.top);
- if(m_pOldBitmap == NULL)
- m_pOldBitmap = SelectObject(&m_bitmap);
- else
- SelectObject(&m_bitmap);
- SetWindowOrg(m_rc.left, m_rc.top);
- }
- }
- void Redraw(CDC * pDC)
- {
- pDC->BitBlt(m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(),
- this, m_rc.left, m_rc.top, SRCCOPY);
- }
- CNCMemDC(CDC* pDC) : CDC()
- {
- ASSERT(pDC != NULL);
- m_pDC = pDC;
- m_pOldBitmap = NULL;
- CreateCompatibleDC(pDC);
- }
- // Destructor copies the contents of the mem DC to the original DC
- ~CNCMemDC()
- {
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- DeleteDC();
- }
- // Allow usage as a pointer
- CNCMemDC* operator->() {return this;}
- // Allow usage as a pointer
- operator CNCMemDC*() {return this;}
- private:
- protected:
- 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.
- CRect m_rc;
- };
- */
- /////////////////////////////////////////////////////////////////////////////
- /*class CNCDraw
- {
- public:
- CNCMemDC m_dcTop;
- CNCMemDC m_dcLeft;
- CNCMemDC m_dcBottom;
- CNCMemDC m_dcRight;
- CNCDraw(CDC* pDC,RECT rcAll,RECT rc)
- :m_dcTop(pDC),m_dcLeft(pDC),m_dcBottom(pDC),m_dcRight(pDC)
- {
- Resize(pDC,rcAll,rc);
- }
- ~CNCDraw()
- {
- }
- void Resize(CDC* pDC,RECT rcAll,RECT rc)
- {
- m_rect = rcAll;
- m_rc = rc;
- {
- m_dcTop.Resize(pDC,rcAll,CRect(m_rect.left,m_rect.top,m_rect.right,m_rect.top+rc.top));
- m_dcLeft.Resize(pDC,rcAll,CRect(m_rect.left,m_rect.top+m_rc.top,m_rc.right,m_rect.bottom));
- m_dcBottom.Resize(pDC,rcAll,CRect(m_rect.left,m_rect.bottom-m_rc.bottom,m_rect.right+m_rc.right,m_rect.bottom));
- m_dcRight.Resize(pDC,rcAll,CRect(m_rect.right-m_rc.right,m_rect.top+m_rc.top,m_rect.right,m_rect.bottom));
- }
- }
- void Redraw(CDC * pDC)
- {
- m_dcTop.Redraw(pDC);
- m_dcLeft.Redraw(pDC);
- m_dcBottom.Redraw(pDC);
- m_dcRight.Redraw(pDC);
- }
- protected:
- CRect m_rc; // Rectangle of drawing area.
- CDC* m_pDC; // Saves CDC passed in constructor
- CRect m_rect; // Rectangle of drawing area.
- };
- */
- class CMemDCEx : public CMemDCBase
- {
- public:
- RECT m_rc;
- CMemDCEx(CDC* pDC,RECT rcAll,RECT rc):CMemDCBase(pDC)
- {
- // BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
- // m_pDC, m_rect.left, m_rect.top, SRCCOPY);
- m_rect = rcAll;
- m_rc = rc;
- 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;
- }
- }
- virtual ~CMemDCEx()
- {
- if (m_bMemDC) {
- // Copy the offscreen bitmap onto the screen.
- m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rc.top,
- this, m_rect.left, m_rect.top, SRCCOPY);
- m_pDC->BitBlt(m_rect.left, m_rect.top, m_rc.left, m_rect.Height(),
- this, m_rect.left, m_rect.top, SRCCOPY);
- m_pDC->BitBlt(m_rect.left, m_rect.bottom-m_rc.bottom, m_rect.Width(), m_rc.bottom,
- this, m_rect.left, m_rect.bottom-m_rc.bottom, SRCCOPY);
- m_pDC->BitBlt(m_rect.right-m_rc.right, m_rect.top,m_rc.right , m_rect.bottom,
- this, m_rect.right-m_rc.right, 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;
- }
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- DeleteDC();
- }
- };
- class CStretchDC : public CDC
- {
- public:
- CRect m_rc;
- CStretchDC(CDC* pDC,RECT rc,RECT rcEx):CDC()
- {
- m_rc = rc;
- // ASSERT(pDC != NULL);
- m_pDC = pDC;
- m_pOldBitmap = NULL;
- m_bMemDC = !pDC->IsPrinting();
- if (m_bMemDC) // Create a Memory DC
- {
- // pDC->GetClipBox(&m_rect);
- m_rect = rcEx;
- CreateCompatibleDC(pDC);
- m_bitmap.CreateCompatibleBitmap(pDC, m_rc.Width(), m_rc.Height());
- m_pOldBitmap = SelectObject(&m_bitmap);
- SetWindowOrg(m_rc.left, m_rc.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;
- }
- }
- virtual ~CStretchDC()
- {
- if (m_bMemDC) {
- // Copy the offscreen bitmap onto the screen.
- m_pDC->StretchBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
- this, m_rc.left, m_rc.top,m_rc.Width(),m_rc.Height(), 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;
- }
- if(m_bitmap.GetSafeHandle() != NULL)
- m_bitmap.DeleteObject();
- }
- protected:
- 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.
- };
- class CLLXMemDC : public CDC {
- private:
- CBitmap* m_bitmap;
- CBitmap* m_oldBitmap;
- CDC* m_pDC;
- CRect m_rcBounds;
- public:
- CLLXMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
- {
- CreateCompatibleDC(pDC);
- m_bitmap = new CBitmap;
- m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(), rcBounds.Height());
- m_oldBitmap = SelectObject(m_bitmap);
- m_pDC = pDC;
- m_rcBounds = rcBounds;
- }
- ~CLLXMemDC()
- {
- m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(), m_rcBounds.Height(),
- this, 0/*m_rcBounds.left, m_rcBounds.top*/,0, SRCCOPY);
- SelectObject(m_oldBitmap);
- if (m_bitmap != NULL) delete m_bitmap;
- }
- CLLXMemDC* operator->() {
- return this;
- }
- };
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)