home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atltangram / atltangramcanvas / atltangramcanvasimpl.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  97 lines

  1. // AtlTangramCanvasImpl.h : Declaration of the CAtlTangramCanvas
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #ifndef __ATLTANGRAMCANVAS_H_
  14. #define __ATLTANGRAMCANVAS_H_
  15.  
  16. #include "resource.h"       // main symbols
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAtlTangramCanvas
  20. class ATL_NO_VTABLE CAtlTangramCanvas : 
  21.     public CComObjectRootEx<CComSingleThreadModel>,
  22.     public CComCoClass<CAtlTangramCanvas, &CLSID_AtlTangramCanvas>,
  23.     public IAtlTangramCanvas
  24. {
  25. public:
  26.     CAtlTangramCanvas():
  27.         m_hWnd(NULL),
  28.         m_hbmp(NULL),
  29.         m_pBits(NULL),
  30.         m_hdc(NULL),
  31.         m_hPal(NULL)
  32.     {
  33.         m_sizeDIB.cx = m_sizeDIB.cy = 0; 
  34.     }
  35.  
  36.     ~CAtlTangramCanvas()
  37.     {
  38.         // Select the old bitmap back into the buffer DC.
  39.         if (m_hbmOld)
  40.         {
  41.             ::SelectObject(m_hdc, m_hbmOld);
  42.         }
  43.  
  44.         // Delete bitmap.
  45.         if (m_hbmp) 
  46.         {
  47.             DeleteObject(m_hbmp);
  48.         }
  49.  
  50.         // Delete DC.
  51.         if (m_hdc) 
  52.         {
  53.             ::DeleteDC(m_hdc) ;
  54.         }
  55.     }
  56.  
  57. DECLARE_REGISTRY_RESOURCEID(IDR_ATLTANGRAMCANVAS)
  58. DECLARE_ONLY_AGGREGATABLE(CAtlTangramCanvas)
  59.  
  60. BEGIN_COM_MAP(CAtlTangramCanvas)
  61.     COM_INTERFACE_ENTRY(IAtlTangramCanvas)
  62. END_COM_MAP()
  63.  
  64. // IAtlTangramCanvas
  65. public:
  66.     virtual HRESULT __stdcall Initialize(HWND hWnd, long cx, long cy) ;//Initialize can be called multiple times.
  67.     virtual HRESULT __stdcall Paint(HDC hdcDest, RECT rectUpdate) ;
  68.     virtual HRESULT __stdcall Update(RECT rectUpdate);
  69.     virtual HRESULT __stdcall GetHDC(HDC* phdc ) ; 
  70.     virtual HRESULT __stdcall SetPalette(HPALETTE hPal); 
  71.     virtual HRESULT __stdcall OnQueryNewPalette(HWND hWndReceived) ;
  72. //Member Variables
  73. private:
  74.     // Handle to window associated with this Canvas.
  75.     HWND m_hWnd ; 
  76.  
  77.     // Handle to dib section.
  78.     HBITMAP m_hbmp ;
  79.  
  80.     // Handle to old bitmap.
  81.     HBITMAP m_hbmOld ;
  82.  
  83.     // Pointer to the bits.
  84.     void* m_pBits ;        
  85.  
  86.     // Size of the canvas.
  87.     SIZE m_sizeDIB ;
  88.  
  89.     // Handle to the device memory context for the dib section.
  90.     HDC m_hdc ;
  91.  
  92.     // Handle to the palette used by the dib section.
  93.     HPALETTE m_hPal;
  94. };
  95.  
  96. #endif //__ATLTANGRAMCANVAS_H_
  97.