home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / DIBSection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  3.2 KB  |  116 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : dibsection.h                                                         //
  12. //  Description: DIB section wrapper, EMF rendering, air brush                       //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. #include "Dib.h"
  17. #include "DDB.h"
  18.  
  19. class KDIBSection : public KDIB, public KDDB
  20. {
  21. public:
  22.     KDIBSection()
  23.     {
  24.     }
  25.  
  26.     virtual ~KDIBSection()
  27.     {
  28.     }
  29.  
  30.     BOOL CreateDIBSection(HDC hDC, CONST BITMAPINFO * pBMI, UINT iUsage, HANDLE hSection, DWORD dwOffset);
  31.     UINT GetColorTable(void);
  32.     UINT SetColorTable(void);
  33.  
  34.     void DecodeDIBSectionFormat(TCHAR desp[]);
  35. };
  36.  
  37. HBITMAP LargestDIBSection(BITMAPINFO * pBMI);
  38.  
  39. void    Frame(HDC hDC, int nFrame, COLORREF crFrame, int left, int top, int right, int bottom);
  40.  
  41. BOOL    SaveWindow(HWND hWnd, bool bClient, int nFrame, COLORREF crFrame);
  42.  
  43.  
  44. // Targa 24-bpp Image using DIB Section
  45. class KTarga24 : public KDIBSection
  46. {
  47. #pragma pack(push,1)
  48.  
  49.     typedef struct    {
  50.         BYTE IDLength;      // 00: length of Identifier string
  51.         BYTE CoMapType;      // 01  0 = no map  
  52.         BYTE ImgType;      // 02  2 = TGA_RGB
  53.         WORD Index;          // 03  index of first color map entry
  54.         WORD Length;      // 05     number of entries in color map
  55.         BYTE CoSize;      // 07  size of color map entry     
  56.         WORD X_Org;       // 08  0
  57.         WORD Y_Org;       // 0A  0
  58.         WORD Width;       // 0C  width
  59.         WORD Height;      // 0E  height
  60.         BYTE PixelSize;   // 10  pixel size
  61.         BYTE AttBits;     // 11  0
  62.         char ID[14];      // 12  space filler to make sure ImageHeader is DWORD aligned
  63.     }    ImageHeader;
  64. #pragma pack(pop)
  65.     
  66.     HANDLE      m_hFile;
  67.     HANDLE      m_hFileMapping;
  68.  
  69. public:
  70.     KTarga24();
  71.     virtual ~KTarga24();
  72.  
  73.     BOOL Create(int width, int height, const TCHAR * filename);
  74. };
  75.  
  76. // Render EMF using memory-mapped Targa file as DIB section
  77. BOOL RenderEMF(HENHMETAFILE hemf, int width, int height, const TCHAR * tgaFileName);
  78.  
  79.  
  80. // Using alpha channel to implement non-solid brush
  81. class KAirBrush
  82. {
  83.     HBITMAP m_hBrush;
  84.     HDC        m_hMemDC;
  85.     HBITMAP m_hOld;
  86.     int        m_nWidth;
  87.     int        m_nHeight;
  88.  
  89.     void Release(void)
  90.     {
  91.         SelectObject(m_hMemDC, m_hOld);
  92.         DeleteObject(m_hMemDC);
  93.         DeleteObject(m_hBrush);
  94.  
  95.         m_hOld = NULL; m_hMemDC = NULL; m_hBrush = NULL;
  96.     }
  97.  
  98. public:
  99.     KAirBrush()
  100.     {
  101.         m_hBrush = NULL;
  102.         m_hMemDC = NULL;
  103.         m_hOld   = NULL;
  104.     }
  105.  
  106.     ~KAirBrush()
  107.     {
  108.         Release();
  109.     }
  110.  
  111.     void Create(int width, int height, COLORREF color);
  112.     void Apply(HDC hDC, int x, int y);
  113. };
  114.  
  115.  
  116.