PJAImage.h
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:4k
源码类别:

CA认证

开发平台:

Visual C++

  1. /****************************************************************************
  2. PJAImage.h : header file for the PJAImage class
  3. written by PJ Arends
  4. pja@telus.net
  5. For updates check http://www3.telus.net/pja/PJAImage.htm
  6. -----------------------------------------------------------------------------
  7. This code is provided as is, with no warranty as to it's suitability or usefulness
  8. in any application in which it may be used. This code has not been tested for
  9. UNICODE builds, nor has it been tested on a network ( with UNC paths ).
  10. This code may be used in any way you desire. This file may be redistributed by any
  11. means as long as it is not sold for profit, and providing that this notice and the
  12. authors name are included.
  13. If any bugs are found and fixed, a note to the author explaining the problem and
  14. fix would be nice.
  15. -----------------------------------------------------------------------------
  16. ****************************************************************************/
  17. #if !defined(AFX_PJAIMAGE_H__F15965B0_B05A_11D4_B625_A1459D96AB20__INCLUDED_)
  18. #define AFX_PJAIMAGE_H__F15965B0_B05A_11D4_B625_A1459D96AB20__INCLUDED_
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif // _MSC_VER > 1000
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPJAImage class
  24. // this class is used to draw an image (HBITMAP or HICON)
  25. // Flags used by the SetImage() function
  26. //
  27. // Usage :
  28. // PJAI_ICON       - the image is an icon, cannot be used with FEC_BITMAP
  29. // PJAI_BITMAP     - the image is a bitmap, cannot be used with FEC_ICON
  30. // PJAI_AUTODELETE - the image handle is deleted and the memory freed when it is no longer needed
  31. #define PJAI_ICON        0x00000001
  32. #define PJAI_BITMAP      0x00000002
  33. #define PJAI_AUTODELETE  0x00000004
  34. // Flags used by the DrawImage() function
  35. //
  36. // Usage :
  37. // PJAI_TRANSPARENT - used with FEC_BITMAP, the bitmap will be drawn transparently
  38. // PJAI_STRETCHED   - Can not be used with PJAI_CENTERED . The image will be stretched to fit the rectangle in DrawImage()
  39. // PJAI_CENTERED    - Can not be used with PJAI_STRETCHED. The image will be centered on the rectangle
  40. // PJAI_DISABLED    - Can not be used with PJAI_GRAYSCALE. Draws the image as disabled (3D Monochrome)
  41. // PJAI_GRAYSCALE   - Can not be used with PJAI_DISABLED. Draws the image in grayscale
  42. #define PJAI_TRANSPARENT 0x00000010
  43. #define PJAI_STRETCHED   0x00000020
  44. #define PJAI_CENTERED    0x00000040
  45. #define PJAI_DISABLED    0x00000080
  46. #define PJAI_GRAYSCALE   0x00000100
  47. class CPJAImage  
  48. {
  49. public:
  50.     CPJAImage();                        // constructor
  51.     virtual ~CPJAImage();               // destructor
  52.     void DrawImage(CDC *pDC, int x, int y, int w, int h, DWORD DrawFlags = 0); // draws the image
  53.     CSize GetSize();                          // retreives the dimensions of the image
  54.     BOOL SetImage(HANDLE Image, DWORD Flags); // setup the image
  55.     COLORREF SetTransparentColour(COLORREF clr = CLR_DEFAULT); // set the colour to used as the transparent colour
  56. protected:
  57.     void DitherBlt(CDC *pToDC, int x, int y, int w, int h, CDC *pFromDC);  // draw the bitmap grayed
  58.     void DrawTransparent(CDC *pToDC, int w, int h, CDC *pFromDC); // draw the bitmap transparently
  59.     int Gray(int r, int g, int b);
  60. HBITMAP GrayScale (CDC *pDC, HBITMAP hBitmap);
  61. BOOL IsTransparent(int r, int g, int b);
  62. private:
  63.     DWORD m_ImageFlags;                 // the control flags
  64.     DWORD m_DrawFlags;                  // the drawing flags
  65.     HANDLE m_hImage;                    // the image
  66.     CSize m_size;                       // the image size
  67.     COLORREF m_TransparentColour;       // the transparent colour
  68. };
  69. #endif