home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / Canvas.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  1.7 KB  |  85 lines

  1. // Canvas.cpp: implementation of the CCanvas class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5.  
  6. #include "Canvas.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13.  
  14. const int nMaxCanvasSize = 256;
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18.  
  19. CCanvas::CCanvas()
  20. {
  21.   m_hDrawWnd = NULL;
  22.   m_nHeight = m_nWidth = nMaxCanvasSize;
  23.   m_bInitialized = false;
  24.   m_hDC = NULL;
  25. }
  26.  
  27. bool CCanvas::Initialize(HWND hWnd, long nWidth, long nHeight)
  28. {  
  29.   m_hDrawWnd = hWnd;
  30.   m_nHeight = nHeight;
  31.   m_nWidth = nWidth;
  32.  
  33.   if(m_bInitialized)
  34.     Deinitialize();
  35.  
  36.   // Create a compatible device context
  37.   HDC hDC = GetDC(m_hDrawWnd);
  38.   
  39.   m_hDC = CreateCompatibleDC( hDC );
  40.  
  41.  
  42.   // Create our bitmap for the memory DC
  43.   m_hBitmap = CreateCompatibleBitmap( hDC, nWidth, nHeight );
  44.   if(!m_hBitmap)
  45.     return false;
  46.  
  47.   ::ReleaseDC(m_hDrawWnd, hDC);
  48.  
  49.   if(!m_hDC)
  50.     return false;
  51.  
  52.  
  53.  
  54.   // Select the bitmap in the device context
  55.   m_hOld = SelectObject( m_hDC, m_hBitmap );
  56.  
  57.   // Set Defaults
  58.   SetBkMode(m_hDC, TRANSPARENT);
  59.  
  60.   m_bInitialized = true;
  61.   return true;
  62. }
  63.  
  64. bool CCanvas::Deinitialize()
  65. {
  66.   SelectObject( m_hDC, m_hOld );
  67.   DeleteObject( m_hBitmap );
  68.   DeleteDC( m_hDC );  
  69.   m_bInitialized = false;
  70.   return true;
  71. }
  72.  
  73. void CCanvas::DrawCanvas(int nXOffset, int nYOffset)
  74. {
  75.   if(!m_bInitialized)
  76.     return;
  77.  
  78.   HDC hDC;
  79.   hDC = GetDC(m_hDrawWnd);
  80.  
  81.   BitBlt( hDC, 0, 0, m_nWidth, m_nHeight, 
  82.           m_hDC, 0, 0, SRCCOPY );
  83.  
  84.   ::ReleaseDC( m_hDrawWnd, hDC );
  85. }