QBufferDC.h
上传用户:xp9161
上传日期:2009-12-21
资源大小:70k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

  1. #pragma once
  2. ///////////////////////////////////////////////////
  3. // QBufferDC
  4. //
  5. // A versatile MFC-class implementing flickerfree, buffered drawing.
  6. // Derived from class CDC and supports all it's operations.
  7. //
  8. // However, all drawing is done to a memory bitmap in stead of to the screen.
  9. // At destruction time, the resulting bitmap is blt'ed to the screen.
  10. //
  11. // Feature: it makes use of 'bounding accumulation' to determine which
  12. // parts of the screen need updating.
  13. //
  14. // Compatible with all mapping modes.
  15. // Compatible with GDI+.
  16. //
  17. // If memory is insufficient to create the buffer bitmap, QBufferDC
  18. // behaves like a normal CDC, without buffered drawing.
  19. //
  20. // QBufferDC's constructor has two parameters:
  21. // pDC points to the mother device context. At destruction time,
  22. // QBufferDC copies the graphics output to this DC;
  23. // dwRopCode the 'ternary raster operation' used for bitblt'ing the
  24. // graphics to the screen. The default just copies; for advanced
  25. // uses, dwRopCode may have another value like SRCINVERT.
  26. //
  27. // QBufferDC clears the buffer bitmap to the background color of the mother DC.
  28. //
  29. // If QBUFFER_DEMO is defined, a special version of this class is compiled.
  30. // It has one extra static member variable, m_bDemoMode. If m_bDemoMode is TRUE
  31. // (default), the background color is slightly and randomly modified, showing
  32. // which parts of the screen are updated.
  33. // QBUFFER_DEMO might be entered as a 'Preprocessor definition' in the project settings.
  34. // In normal use, QBUFFER_DEMO should not be defined.
  35. ////////////////////////////////////////////////////
  36. //
  37. // (c) Sjaak Priester, Amsterdam, 2003.
  38. // www.sjaakpriester.nl
  39. ////////////////////////////////////////////////////
  40. // Microsoft defined for 17 of the 255 possible 'ternary raster operations' a mnemonic
  41. // name like SRCCOPY or PATINVERT. They really should have defined this one too,
  42. // because it goes well with the R2_NOTXORPEN secondary raster operation, which
  43. // comes in handy for rubber banding applications. It might be used as dwRopCode
  44. // in constructing a QBufferDC.
  45. #ifndef NOTSRCINVERT
  46. #define NOTSRCINVERT 0x00990066 // DSxn => Destination, Source, xor, not
  47. #endif
  48. class QBufferDC : public CDC
  49. {
  50. public:
  51. // Construction
  52. QBufferDC(CDC * pDC, DWORD dwRopCode = SRCCOPY);
  53. virtual ~QBufferDC();
  54. protected:
  55. // Implementation
  56. CDC *m_pDC; // The mother DC
  57. DWORD m_RopCode; // The rop code used for bitblt'ing the final result
  58. private:
  59. CBitmap *m_pOldBitmap;
  60. // Helper class
  61. static class BufferBitmap
  62. {
  63. public:
  64. BOOL ReserveBitmap(CDC * pDC, CSize sz);
  65. BOOL IsValid() const { return m_Bitmap.GetSafeHandle() != NULL; }
  66. CBitmap m_Bitmap;
  67. } m_BufferBitmap;
  68. #ifdef QBUFFER_DEMO
  69. public:
  70. static BOOL m_bDemoMode;
  71. #endif
  72. };