www.pudn.com > VC写的MP3播放器源代码.zip > GWExtDIBSectionLite.h
// GWExtDIBSectionLite.h: interface for the GWExtDIBSectionLite class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_GWEXTDIBSECTIONLITE_H__8AD9D763_7EBD_11DA_B5EA_525400EA266C__INCLUDED_) #define AFX_GWEXTDIBSECTIONLITE_H__8AD9D763_7EBD_11DA_B5EA_525400EA266C__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 //******************************************************************************* // 版权声明 // ------------------------------------------------------------------------------ // 此段代码是AppBuilder扩展类库GWC的一部分. // 你可以使用、重新编译、或者编译成你的发行软件的一部分。 // 但是在没有经过我们书面同意的情况下,你不能直接发行此代码文件. //------------------------------------------------------------------------------- // 版权所有. // 作者:张修勇 // 拷贝日期:2000年10月05日 //------------------------------------------------------------------------------- // 主页: http://www.ucancode.com // 技术支持E-Mail: AppBuilder@hotmail.com //******************************************************************************* //#define DIBSECTION_NO_DITHER // Disallow dithering via DrawDib functions #define DIBSECTION_NO_MEMDC_REUSE // Disallow the reuse of memory DC's //#define DIBSECTION_NO_PALETTE // Remove palette support // Only provide palette support for non-CE platforms, or for CE 2.11 and above #ifdef _WIN32_WCE #define DIBSECTION_NO_DITHER // DrawDib not supported on CE #if (_WIN32_WCE < 211) #define DIBSECTION_NO_PALETTE // No palette support on early CE devices #endif #endif // Include headers and lib for DrawDib routines #ifndef DIBSECTION_NO_DITHER #include#pragma comment(lib, "vfw32") #endif #define DS_BITMAP_FILEMARKER ((WORD) ('M' << 8) | 'B') // is always "BM" = 0x4D42 ///////////////////////////////////////////////////////////////////////////// // BITMAPINFO wrapper struct DIBINFO : public BITMAPINFO { RGBQUAD arColors[255]; // Color table info - adds an extra 255 entries to palette operator LPBITMAPINFO() { return (LPBITMAPINFO) this; } operator LPBITMAPINFOHEADER() { return &bmiHeader; } RGBQUAD* ColorTable() { return bmiColors; } }; ///////////////////////////////////////////////////////////////////////////// // LOGPALETTE wrapper #ifndef DIBSECTION_NO_PALETTE struct PALETTEINFO : public LOGPALETTE { PALETTEENTRY arPalEntries[255]; // Palette entries PALETTEINFO() { palVersion = (WORD) 0x300; palNumEntries = 0; ::memset(palPalEntry, 0, 256*sizeof(PALETTEENTRY)); } operator LPLOGPALETTE() { return (LPLOGPALETTE) this; } operator LPPALETTEENTRY() { return (LPPALETTEENTRY) (palPalEntry); } }; #endif // DIBSECTION_NO_PALETTE ///////////////////////////////////////////////////////////////////////////// // GWExtDIBSectionLite object class GWExtDIBSectionLite : public CObject { // Construction public: GWExtDIBSectionLite(); virtual ~GWExtDIBSectionLite(); void DeleteObject(); // static helpers public: static int BytesPerLine(int nWidth, int nBitsPerPixel); static int NumColorEntries(int nBitsPerPixel, int nCompression); static RGBQUAD ms_StdColors[]; #ifndef DIBSECTION_NO_PALETTE static BOOL UsesPalette(CDC* pDC) { return (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE); } static BOOL CreateHalftonePalette(CPalette& palette, int nNumColors); #endif // DIBSECTION_NO_PALETTE // Attributes public: HBITMAP GetSafeHandle() const { return (this)? m_hBitmap : NULL; } operator HBITMAP() const { return GetSafeHandle(); } CSize GetSize() const { return CSize(GetWidth(), GetHeight()); } int GetHeight() const { return m_DIBinfo.bmiHeader.biHeight; } int GetWidth() const { return m_DIBinfo.bmiHeader.biWidth; } int GetPlanes() const { return m_DIBinfo.bmiHeader.biPlanes; } int GetBitCount() const { return m_DIBinfo.bmiHeader.biBitCount; } LPVOID GetDIBits() { return m_ppvBits; } LPBITMAPINFO GetBitmapInfo() { return (BITMAPINFO*) m_DIBinfo; } DWORD GetImageSize() const { return m_DIBinfo.bmiHeader.biSizeImage; } LPBITMAPINFOHEADER GetBitmapInfoHeader() { return (BITMAPINFOHEADER*) m_DIBinfo; } // Operations (Palette) public: LPRGBQUAD GetColorTable() { return m_DIBinfo.ColorTable(); } BOOL SetColorTable(UINT nNumColors, RGBQUAD *pColors); int GetColorTableSize() { return m_iColorTableSize; } #ifndef DIBSECTION_NO_PALETTE CPalette *GetPalette() { return &m_Palette; } BOOL SetPalette(CPalette* pPalette); BOOL SetLogPalette(LOGPALETTE* pLogPalette); #endif // DIBSECTION_NO_PALETTE // Operations (Setting the bitmap) public: BOOL SetBitmap(UINT nIDResource); BOOL SetBitmap(LPCTSTR lpszResourceName); BOOL SetBitmap(HBITMAP hBitmap #ifndef DIBSECTION_NO_PALETTE , CPalette* pPalette = NULL #endif ); BOOL SetBitmap(LPBITMAPINFO lpBitmapInfo, LPVOID lpBits); BOOL Load(LPCTSTR lpszFileName); BOOL Save(LPCTSTR lpszFileName); BOOL Copy(GWExtDIBSectionLite& Bitmap); // Operations (Display) public: BOOL Draw(CDC* pDC, CPoint ptDest, BOOL bForceBackground = FALSE); BOOL Stretch(CDC* pDC, CPoint ptDest, CSize size, BOOL bForceBackground = FALSE); #ifndef DIBSECTION_NO_DITHER BOOL SetDither(BOOL bDither); BOOL GetDither(); #endif // DIBSECTION_NO_DITHER CDC* GetMemoryDC(CDC* pDC = NULL, BOOL bSelectPalette = TRUE); BOOL ReleaseMemoryDC(BOOL bForceRelease = FALSE); // Overrideables // Implementation public: #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif // Implementation protected: void _ShowLastError(); #ifndef DIBSECTION_NO_PALETTE BOOL CreatePalette(); BOOL FillDIBColorTable(UINT nNumColors, RGBQUAD *pRGB); #endif // DIBSECTION_NO_PALETTE UINT GetColorTableEntries(HDC hdc, HBITMAP hBitmap); #ifndef DIBSECTION_NO_DITHER HDRAWDIB GetDrawDibContext(); #endif // DIBSECTION_NO_DITHER protected: HBITMAP m_hBitmap; // Handle to DIBSECTION DIBINFO m_DIBinfo; // Bitmap header & color table info VOID *m_ppvBits; // Pointer to bitmap bits UINT m_iColorDataType; // color data type (palette or RGB values) UINT m_iColorTableSize; // Size of color table CDC m_MemDC; // Memory DC for drawing on bitmap #ifndef DIBSECTION_NO_DITHER BOOL m_bDither; // Use DrawDib routines for dithering? HDRAWDIB m_hDrawDib; // handle to a DrawDib DC #endif #ifndef DIBSECTION_NO_MEMDC_REUSE BOOL m_bReuseMemDC; // Reeuse the memory DC? (Quicker, but not fully tested) #endif #ifndef DIBSECTION_NO_PALETTE CPalette m_Palette; // Color palette CPalette *m_pOldPalette; #endif // DIBSECTION_NO_PALETTE private: HBITMAP m_hOldBitmap; // Storage for previous bitmap in Memory DC }; #endif // !defined(AFX_GWEXTDIBSECTIONLITE_H__8AD9D763_7EBD_11DA_B5EA_525400EA266C__INCLUDED_)