Bitmap32.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 3k
Category:

Graph program

Development Platform:

Visual C++

  1. #pragma once
  2. #include "afxwin.h"
  3. #include <vector>
  4. using std::vector;
  5. typedef struct {
  6. BYTE red;
  7. BYTE green;
  8. BYTE blue;
  9. BYTE alpha;
  10. } RGBA8, *LPRGBA8;
  11. typedef struct {
  12. UINT nCount;
  13. LPBITMAPINFO* ppbi;
  14. } ICONSDATA, *LPICONSDATA;
  15. typedef struct
  16. {
  17. BYTE bWidth;               // Width of the image
  18. BYTE bHeight;              // Height of the image (times 2)
  19. BYTE bColorCount;          // Number of colors in image (0 if >=8bpp)
  20. BYTE bReserved;            // Reserved
  21. WORD wPlanes;              // Color Planes
  22. WORD wBitCount;            // Bits per pixel
  23. DWORD dwBytesInRes;         // how many bytes in this resource?
  24. DWORD dwImageOffset;        // where in the file is this image
  25. } _ICONDIRENTRY, *_LPICONDIRENTRY;
  26. HBITMAP CombineResources( int cy, ... );
  27. HBITMAP CombineBitmaps( int cy, ... );
  28. HBITMAP Combine( int cx, int cy, vector<LPBITMAP> *lstSrc );
  29. BOOL LoadBitmap32( LPTSTR pszFile, LPBITMAP bmp );
  30. int SaveBitmap( HBITMAP hBMP, LPTSTR pszFile );
  31. int GetBitmapInfo( HBITMAP hBMP, LPBITMAPINFO pbi );
  32. HBITMAP LoadBitmap32 ( LPCTSTR lpszResourceName, LPLONG lpnWidth = NULL, LPLONG lpnHeight = NULL, LPWORD lpnBitCount = NULL, HINSTANCE hInst = NULL);
  33. BOOL LoadIcon32(  LPCTSTR lpszFilename, LPICONSDATA lpid );
  34. class CSurface
  35. {
  36. CDC * m_pLockedDC;
  37. CDC m_SurfaceDC;
  38. HBITMAP m_hBitmap;
  39. HBITMAP m_hOldBitmap;
  40. int m_nXOffset;
  41. int m_nYOffset;
  42. int m_nWidth;
  43. int m_nHeight;
  44. CRect m_rcBounds;
  45. public:
  46. CSurface( );
  47. CDC * Lock( CDC * pDC, CRect* prcBounds );
  48. void Release();
  49. void GetSizes( int *pnWidth, int * pnHeight ) { *pnWidth = m_nWidth; *pnHeight = m_nHeight; }
  50. CRect * GetBounds() { return &m_rcBounds; }
  51. LPRGBA8 m_pBits;
  52. };
  53. class CBitmap32 :
  54. public CBitmap
  55. {
  56. LPRGBA8 m_pBits;
  57. int m_nWidth;
  58. int m_nHeight;
  59. public:
  60. CBitmap32(void);
  61. ~CBitmap32(void);
  62. int GetWidth() { return m_nWidth; }
  63. int GetHeight() { return m_nHeight; }
  64. void SetHeight( int nHeight ) { m_nHeight = nHeight; }
  65. BOOL Attach( HGDIOBJ hObject, LPWORD lpwColors );
  66. BOOL DeleteObject();
  67. BOOL LoadBitmap( UINT nIDResource, HINSTANCE hInst = NULL );
  68. BOOL LoadBitmap( LPCTSTR lpszResourceName, HINSTANCE hInst = NULL );
  69. BOOL AddBitmap( HBITMAP hBitmap, LPWORD lpwColors );
  70. BOOL AddBitmap( UINT nIDResource, HINSTANCE hInst = NULL );
  71. BOOL AddBitmap( LPCTSTR lpszResourceName, HINSTANCE hInst = NULL );
  72. void GetSurface( CDC * pDC, const CRect *pRect, CDC *pSurfaceDC, LPRGBA8 * ppSurfaceBits, HBITMAP * phSurface );
  73. void Draw(CDC *pDC, CRect* prcDest, CRect* prcSrc, int nMode = 0);
  74. void StretchDraw(CDC *pDC, CRect* prcDest, CRect* prcSrc, int nMode = 0);
  75. void StretchDrawEx( CDC * pDC, const CRect* prcDest, const CRect* prcSrc, int nMode = 0 );
  76. };