• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我的玻璃盒子

            一個(gè)圖片加載與繪制類(使用GDI輸出圖片)

            這是一個(gè)圖片加載與繪制的類,使用GDI將圖片文件繪制到DC上,可以用于圖片顯示,程序換膚等應(yīng)用場合。
            其中部分代碼來源于互聯(lián)網(wǎng),代碼作者不詳,我只進(jìn)行了改進(jìn)和增補(bǔ),如果來源作者看到,還望諒解。

            一、頭文件(CEnBitmap.h)

            /**///////////////////////////////////////////////////////////////////////////
            ///    
            ///    @file    EnBitmap.h
            ///    
            ///    @brief    Inherite from CBitmap, expanding some draw features
            ///    
            ///    @author    XuYu
            ///    @version    1.0
            ///    @date    2007-07-26
            ///
            //////////////////////////////////////////////////////////////////////////


            #if !defined(AFX_ENBITMAP_H__76F269F6_895A_48EC_BA09_7D3BEF0438E7__INCLUDED_)
            #define AFX_ENBITMAP_H__76F269F6_895A_48EC_BA09_7D3BEF0438E7__INCLUDED_

            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000

            class CEnBitmap : public CBitmap 
            {
            public:
                CEnBitmap();
                
            virtual ~CEnBitmap();

                BOOL LoadImage(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst 
            = NULL, COLORREF crBack = 0);
                BOOL LoadImage(LPCTSTR lpctImagePath, COLORREF crBack
            =0);
                BOOL LoadImage(HBITMAP hBitmap);
                BOOL LoadImage2(UINT uIDRes, LPCTSTR lpctResType, HMODULE hInst
            =NULL, COLORREF crBack=0);
                
            int GetWidth()
                
            {
                    BITMAP bm;
                    memset( 
            &bm, 0sizeof(bm) );
                    GetBitmap(
            &bm);
                    
            return bm.bmWidth;
                }

                
            int GetHeight()
                
            {
                    BITMAP bm;
                    memset( 
            &bm, 0sizeof(bm) );
                    GetBitmap(
            &bm);
                    
            return bm.bmHeight;
                }

                CRect GetRect()
                
            {
                    
            return CRect(00, GetWidth(), GetHeight());
                }

                BOOL ExtendDraw(CDC 
            *pDC,CRect rc, int nX, int nY);
                BOOL ExtendDrawImage(CEnBitmap 
            &bmp, CRect rc, int nX, int nY);
                BOOL StretchDraw(CDC 
            *pDC, LPRECT r, LPRECT sr);
                BOOL StretchDraw(CDC 
            *pDC, LPRECT r);
                BOOL Draw(CDC 
            *pDC, LPRECT r);
                
            private:
                
            static int GetImageType(LPCTSTR lpctImagePath);
                
            static HBITMAP ExtractBitmap(IPicture* pPicture, COLORREF crBack = 0);
                
            static HBITMAP LoadImageFile(LPCTSTR lpctImagePath, COLORREF crBack = 0);
                
            static HBITMAP LoadImageResource(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst = NULL, COLORREF crBack = 0);

                
            static BOOL GetResource(LPCTSTR lpctName, LPCTSTR lpctType, HMODULE hInst, void* pRes, int& nBufSize);
                
            static IPicture* LoadFromBuffer(BYTE* pBuff, int nSize);
                BOOL AttachEx(IPicture
            * pPicture, COLORREF crBack);
            }
            ;

            #endif // !defined(AFX_ENBITMAP_H__76F269F6_895A_48EC_BA09_7D3BEF0438E7__INCLUDED_)

            二、源文件(CEnBitmap.cpp)
            #include "stdafx.h"
            #include 
            "EnBitmap.h"

            /**//// Definition of picture type
            enum 
            {
                FT_BMP,
                FT_JPG,
                FT_UNKNOWN
            }
            ;

            CEnBitmap::CEnBitmap()
            {

            }


            CEnBitmap::
            ~CEnBitmap()
            {
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Get picture type, only support JPG and BMP
            ///
            ///    @param [in] lpctImagePath    The picture full path
            ///
            //////////////////////////////////////////////////////////////////////////

            int CEnBitmap::GetImageType(LPCTSTR lpctImagePath)
            {
                size_t nLen 
            = _tcslen(lpctImagePath);
                TCHAR
            * lptImagePath = new TCHAR[nLen+1];
                memset(lptImagePath,
            0,nLen+1);
                _tcscpy(lptImagePath, lpctImagePath);
                
                CharUpper(lptImagePath);
                
                TCHAR lptExtension[
            5= {0};
                size_t i
            =nLen-4;
                size_t j
            =0;
                
            for(; i<nLen; i++,j++)
                    lptExtension[j] 
            = lptImagePath[i];
                
                delete[] lptImagePath;
                
                
            if(_tcscmp(lptExtension,_T(".BMP")) == 0)
                    
            return FT_BMP;
                
            if(_tcscmp(lptExtension,_T(".JPG")) == 0)
                    
            return FT_JPG;
                
                
            return FT_UNKNOWN;
            }

            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Extract a picture use IPicture interface
            ///
            ///    @param [in] pPicture    IPicture interface pointer
            ///    @param [in] crBack        Mask color to make transparent
            ///
            //////////////////////////////////////////////////////////////////////////

            HBITMAP CEnBitmap::ExtractBitmap(IPicture* pPicture, COLORREF crBack /**//* = 0 */)
            {
                ATLASSERT(pPicture);
                
                
            if (!pPicture)
                    
            return NULL;
                
                CBitmap bmMem;
                CDC dcMem;
                HWND hwndDesktopWnd 
            = ::GetDesktopWindow();
                HDC hDesktopDC 
            = ::GetDC(hwndDesktopWnd);
                CDC
            * pDC = new CDC(hDesktopDC);
                
                
            if (dcMem.CreateCompatibleDC(pDC->m_hDC))
                
            {
                    
            long hmWidth;
                    
            long hmHeight;
                    
                    pPicture
            ->get_Width(&hmWidth);
                    pPicture
            ->get_Height(&hmHeight);
                    
                    
            int nWidth    = MulDiv(hmWidth, pDC->GetDeviceCaps(LOGPIXELSX), HIMETRIC_INCH);
                    
            int nHeight    = MulDiv(hmHeight, pDC->GetDeviceCaps(LOGPIXELSY), HIMETRIC_INCH);
                    
                    
            if (bmMem.CreateCompatibleBitmap(pDC->m_hDC, nWidth, nHeight))
                    
            {
                        HBITMAP hOldBM 
            = dcMem.SelectBitmap(bmMem.m_hBitmap);
                        
                        
            if (crBack != -1)
                            dcMem.FillSolidRect(
            00, nWidth, nHeight, crBack);
                        
                        HRESULT hr 
            = pPicture->Render(dcMem, 00, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, NULL);
                        dcMem.SelectBitmap(hOldBM);
                    }

                }

                
                ::ReleaseDC(hwndDesktopWnd, pDC
            ->m_hDC);
                
            if(dcMem.m_hDC) ::DeleteDC(dcMem.Detach());
                ::DeleteObject(hDesktopDC);
                
            if(pDC->m_hDC) ::DeleteDC(pDC->Detach());
                
                
            return (HBITMAP)bmMem.Detach();
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a picture from full path
            ///
            ///    @param [in] lpctImagePath    The full path of picture
            ///    @param [in] crBack        Mask color to make transparent
            ///
            //////////////////////////////////////////////////////////////////////////

            HBITMAP CEnBitmap::LoadImageFile(LPCTSTR lpctImagePath, COLORREF crBack /**//* = 0 */)
            {
                
            int nImgType = GetImageType(lpctImagePath);
                USES_CONVERSION;

                
            switch(nImgType)
                
            {
                
            case FT_BMP:
                    
            return (HBITMAP)::LoadImage(NULL, lpctImagePath, IMAGE_BITMAP, 00, LR_LOADFROMFILE);
                
            case FT_UNKNOWN:
                    
            return NULL;
                
            default:
                    
            {
                        IPicture
            * pPic = NULL;
                        HBITMAP hbm 
            = NULL;
                        HRESULT hr 
            = OleLoadPicturePath(T2OLE((LPTSTR)lpctImagePath), NULL, 0, crBack, IID_IPicture, (LPVOID *)&pPic);
                        
            if(pPic)
                        
            {
                            hbm 
            = ExtractBitmap(pPic, crBack);
                            pPic
            ->Release();
                        }

                        
                        
            return hbm;
                    }

                }

                
                
            return NULL;
            }

            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a picture from resource ID
            ///
            ///    @param [in] uIDRes    Resource ID
            ///    @param [in] szResourceType    Resource type
            ///    @param [in] hInst    Instance including resources
            ///    @param [in] crBack        Mask color to make transparent
            ///
            ///    @note This method need to valid
            ///
            //////////////////////////////////////////////////////////////////////////

            HBITMAP CEnBitmap::LoadImageResource(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst /**//* = NULL */, COLORREF crBack /**//* = 0 */)
            {
                BYTE
            * pBuff = NULL;
                
            int nSize = 0;
                HBITMAP hbm 
            = NULL;
                
                
            // first call is to get buffer size
                if (GetResource(MAKEINTRESOURCE(uIDRes), szResourceType, hInst, 0, nSize))
                
            {
                    
            if (nSize > 0)
                    
            {
                        pBuff 
            = new BYTE[nSize];
                        
                        
            // this loads it
                        if (GetResource(MAKEINTRESOURCE(uIDRes), szResourceType, hInst, pBuff, nSize))
                        
            {
                            IPicture
            * pPicture = LoadFromBuffer(pBuff, nSize);
                            
                            
            if (pPicture)
                            
            {
                                hbm 
            = ExtractBitmap(pPicture, crBack);
                                pPicture
            ->Release();
                            }

                        }

                        
                        delete [] pBuff;
                    }

                }

                
                
            return hbm;
            }

            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a picture from full path of picture
            ///
            ///    @param [in] lpctImagePath    Full path of picture
            ///    @param [in] crBack        Mask color to make transparent
            ///
            ///    @note This is the entry method
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::LoadImage(LPCTSTR lpctImagePath, COLORREF crBack/**//* =0 */)
            {
                
            if(m_hBitmap != NULL)
                
            {
                    DeleteObject();
                    Detach();
                }

                
                Attach(LoadImageFile(lpctImagePath, crBack));
                
                
            return (m_hBitmap == NULL) ? FALSE : TRUE;
            }

            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a picture from resource ID and type
            ///
            ///    @param [in] uIDRes    Resource ID
            ///    @param [in] szResourceType    Resource type
            ///    @param [in] hInst    Instance including resources
            ///    @param [in] crBack        Mask color to make transparent
            ///
            ///    @note This is the entry method
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::LoadImage(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst /**//* = NULL */, COLORREF crBack /**//* = 0 */)
            {
                ATLASSERT(m_hBitmap 
            == NULL);
                
                
            if (m_hBitmap != NULL)
                    
            return TRUE;
                
                Attach(LoadImageResource(uIDRes, szResourceType, hInst, crBack));

                
            return (m_hBitmap == NULL) ? FALSE : TRUE;
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a bitmap from handle
            ///
            ///    @param [in] hBitmap    Handle of a bitmap
            ///
            ///    @note This method need to valid
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::LoadImage(HBITMAP hBitmap)
            {
                
            if(m_hBitmap != NULL)
                
            {
                    DeleteObject();
                    Detach();
                }


                Attach(hBitmap);

                
            return (m_hBitmap == NULL) ? FALSE : TRUE;
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Load a picture from resource ID
            ///
            ///    @param [in] uIDRes    Resource ID
            ///    @param [in] szResourceType    Resource type
            ///    @param [in] hInst    Instance including resources
            ///    @param [in] crBack        Mask color to make transparent
            ///
            ///    @note This method is just for TESTING, DONT'T CALL this method before validation
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::LoadImage2(UINT uIDRes, LPCTSTR lpctResType, HMODULE hInst/**//* =NULL */, COLORREF crBack/**//* =0 */)
            {
                ATLASSERT(m_hBitmap 
            == NULL);      // only attach once, detach on destroy
                
            //     if (m_hBitmap != NULL)
            //         return FALSE;
            //     if( (m_hBitmap = ::LoadBitmap(_Module.m_hInst,MAKEINTRESOURCE(uIDRes)) ) != NULL)
            //         return TRUE;
            // 
            //     return FALSE;    

                BYTE
            *    pBuff = NULL;
                
            int        nSize = 0;
                BOOL bResult 
            = FALSE;
                
                
            // first call is to get buffer size
                if (GetResource(MAKEINTRESOURCE(uIDRes), lpctResType, hInst, 0, nSize))
                
            {
                    
            if (nSize > 0)
                    
            {
                        pBuff 
            = new BYTE[nSize];
                        
                        
            // this loads it
                        if (GetResource(MAKEINTRESOURCE(uIDRes), lpctResType, hInst, pBuff, nSize))
                        
            {
                            IPicture
            * pPicture = LoadFromBuffer(pBuff, nSize);
                            
                            
            if (pPicture)
                            
            {
                                bResult 
            = AttachEx(pPicture, crBack);
                                pPicture
            ->Release();
                            }

                        }

                        
                        delete [] pBuff;
                    }

                }

                
                
            return bResult;
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Make a IPicture interface pointer from buffer stream
            ///
            ///    @param [in] pBuff    Picture buffer stream
            ///    @param [in] nSize    Size of pBuff
            ///
            ///    @note This method need to valid
            ///
            //////////////////////////////////////////////////////////////////////////

            IPicture* CEnBitmap::LoadFromBuffer(BYTE* pBuff, int nSize)
            {
                
            bool bResult = false;

                HGLOBAL hGlobal 
            = GlobalAlloc(GMEM_MOVEABLE, nSize);
                
            void* pData = GlobalLock(hGlobal);
                memcpy(pData, pBuff, nSize);
                GlobalUnlock(hGlobal);

                IStream
            * pStream = NULL;
                IPicture
            * pPicture = NULL;

                
            if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
                
            {
                    HRESULT hr 
            = ::OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&pPicture);
                    pStream
            ->Release();
                }


                ::GlobalFree(hGlobal);

                
            return pPicture; // caller releases
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Get resource from a module
            ///
            ///    @param [in] lpName    Resource name
            ///    @param [in] lpType    Resource type
            ///    @param [in] hInst    Handle of module
            ///    @param [out] pResource    Resource pointer
            ///    @param [in] nBufSize    Size of resource
            ///
            ///    @note This method need to valid
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::GetResource(LPCTSTR lpName, LPCTSTR lpType, HMODULE hInst, void* pResource, int& nBufSize)

                HRSRC        hResInfo;
                HANDLE        hRes;
                LPSTR        lpRes    
            = NULL; 
                
            int            nLen    = 0;
                
            bool        bResult    = FALSE;

                
            // Find the resource
                hResInfo = FindResource(hInst, lpName, lpType);

                
            if (hResInfo == NULL) 
                    
            return false;

                
            // Load the resource
                hRes = LoadResource(hInst, hResInfo);

                
            if (hRes == NULL) 
                    
            return false;

                
            // Lock the resource
                lpRes = (char*)LockResource(hRes);

                
            if (lpRes != NULL)
                

                    
            if (pResource == NULL)
                    
            {
                        nBufSize 
            = SizeofResource(hInst, hResInfo);
                        bResult 
            = true;
                    }

                    
            else
                    
            {
                        
            if (nBufSize >= (int)SizeofResource(hInst, hResInfo))
                        
            {
                            memcpy(pResource, lpRes, nBufSize);
                            bResult 
            = true;
                        }

                    }
             

                    UnlockResource(hRes);  
                }


                
            // Free the resource
                FreeResource(hRes);

                
            return bResult;
            }


            /**///////////////////////////////////////////////////////////////////////////
            ///
            ///    @brief    Attach a picture from IPicture interface pointer
            ///
            ///    @param [in] pPicture    IPicture interface pointer
            ///    @param [in] crBack    Mask color for making transparent
            ///
            ///    @note    This method is called by LoadImage2, a TESTING function, 
            ///            so DON'T USE THIS METHOD before validation
            ///
            //////////////////////////////////////////////////////////////////////////

            BOOL CEnBitmap::AttachEx(IPicture* pPicture, COLORREF crBack)
            {
                ATLASSERT(m_hBitmap 
            == NULL);      // only attach once, detach on destroy

                
            if (m_hBitmap != NULL)
                    
            return FALSE;

                ATLASSERT(pPicture);

                
            if (!pPicture)
                    
            return FALSE;

                BOOL bResult 
            = FALSE;

                CDC dcMem;
                CWindowDC dc(GetDesktopWindow());
                CDC
            * pDC = &dc;

                
            if (dcMem.CreateCompatibleDC(pDC->m_hDC))
                
            {
                    
            long hmWidth;
                    
            long hmHeight;

                    pPicture
            ->get_Width(&hmWidth);
                    pPicture
            ->get_Height(&hmHeight);
                    
                    
            int nWidth    = MulDiv(hmWidth,    pDC->GetDeviceCaps(LOGPIXELSX), HIMETRIC_INCH);
                    
            int nHeight    = MulDiv(hmHeight,    pDC->GetDeviceCaps(LOGPIXELSY), HIMETRIC_INCH);

                    CBitmap bmMem;

                    
            if (bmMem.CreateCompatibleBitmap(pDC->m_hDC, nWidth, nHeight))
                    
            {
                        HBITMAP hOldBM 
            = dcMem.SelectBitmap(bmMem.m_hBitmap);

                        
            if (crBack != -1)
                            dcMem.FillSolidRect(
            00, nWidth, nHeight, crBack);
                        
                        HRESULT hr 
            = pPicture->Render(dcMem, 00, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, NULL);
                        dcMem.SelectBitmap(hOldBM);

                        
            if (hr == S_OK)
                            
            /**//*bResult = */CBitmap::Attach(bmMem.Detach());    
                    }


                    
            if(bmMem.m_hBitmap) bmMem.DeleteObject();
                }


                ReleaseDC(GetDesktopWindow(),pDC
            ->m_hDC);
                
            if(dcMem.m_hDC) ::DeleteDC(dcMem.Detach());

                
            return bResult;
            }


            BOOL CEnBitmap::ExtendDraw(CDC 
            *pDC, CRect rc, int nX, int nY)
            {
                CEnBitmap bmp;
                
            if (ExtendDrawImage(bmp,rc,nX,nY))
                
            {
                    bmp.Draw(pDC, 
            &rc); 
                    
            return TRUE;
                }

                
            return FALSE;
            }


            BOOL CEnBitmap::ExtendDrawImage(CEnBitmap 
            &bmp, CRect rc, int nX, int nY)
            {
                HBITMAP hOldBmp;
                CDC memDC;
                CClientDC cdc(
            0);
                
                memDC.CreateCompatibleDC(cdc.m_hDC);
                bmp.CreateCompatibleBitmap(cdc.m_hDC, rc.Width() , rc.Height() );
                hOldBmp 
            = memDC.SelectBitmap( bmp.m_hBitmap );
                
                
            if (nX==0 && nY==0)
                
            {
                    StretchDraw(
            &memDC, &rc, GetRect());
                    
            return TRUE;
                }


                CDC dc;
                dc.CreateCompatibleDC(memDC.m_hDC);
                HBITMAP hBmp 
            = dc.SelectBitmap( m_hBitmap );
                
            //dc.SetStretchBltMode(COLORONCOLOR);
                if (nX!=0 && nY==0)
                
            {
                    
                    
            //左上角
                    memDC.BitBlt( 00, nX, rc.Height(), dc.m_hDC, 00, SRCCOPY );
                    memDC.StretchBlt(nX, 
            0, rc.Width()-GetWidth(), rc.Height(), dc.m_hDC,nX, 01, GetHeight(), SRCCOPY );
                    
            //右上角
                    memDC.BitBlt(rc.right-(GetWidth()-nX), 0, GetWidth()-nX, rc.Height(), dc.m_hDC,nX, 0, SRCCOPY );
                    
                }

                
            else if (nX==0 && nY!=0)
                
            {
                    
            //上角
                    memDC.BitBlt( 00, rc.Width(), nY, dc.m_hDC, 00, SRCCOPY );
                    memDC.StretchBlt(
            0, nY, GetWidth(), rc.Height()-GetHeight(), dc.m_hDC,0, nY, GetWidth(), 1, SRCCOPY );
                    
            //右上角
                    memDC.BitBlt(0, rc.bottom-(GetHeight()-nY), GetWidth(), GetHeight()-nY, dc.m_hDC,0, nY, SRCCOPY );
                    
                }

                
            else
                
            {
                    
            //左上角
                    memDC.StretchBlt( 00, nX, nY, dc.m_hDC, 00, nX, nY, SRCCOPY );
                    
            //上中
                    memDC.StretchBlt(nX, 0, rc.Width()-GetWidth(),nY, dc.m_hDC, nX, 01, nY , SRCCOPY );
                    
            //右上角
                    memDC.StretchBlt(rc.Width()-(GetWidth()-nX), 0, GetWidth()-nX, nY ,  dc.m_hDC,nX, 0, GetWidth()-nX, nY, SRCCOPY );
                    
            //左中
                    memDC.StretchBlt(0, nY, nX,rc.Height()-GetHeight(), dc.m_hDC, 0, nY, nX, 1, SRCCOPY );
                    
            //正中
                    memDC.StretchBlt(nX, nY, rc.Width()-GetWidth(),rc.Height()-GetHeight(), dc.m_hDC, nX, nY, 11, SRCCOPY );
                    
            //右中
                    memDC.StretchBlt(rc.Width()-(GetWidth()-nX), nY, GetWidth()-nX,rc.Height()-GetHeight(), dc.m_hDC, nX, nY, GetWidth()-nX, 1, SRCCOPY );
                    
            //左下角
                    memDC.StretchBlt( 0, rc.Height()-(GetHeight()-nY), nX, GetHeight()-nY, dc.m_hDC, 0, nY, nX,GetHeight()-nY , SRCCOPY );
                    
            //下中
                    memDC.StretchBlt(nX, rc.Height()-(GetHeight()-nY), rc.Width()-GetWidth(),GetHeight()-nY, dc.m_hDC, nX, nY, 1, GetHeight()-nY, SRCCOPY );
                    
            //右下角
                    memDC.StretchBlt( rc.Width()-(GetWidth()-nX), rc.Height()-(GetHeight()-nY), GetWidth()-nX, GetHeight()-nY, dc.m_hDC, nX, nY, GetWidth()-nX, GetHeight()-nY, SRCCOPY );
                }

                dc.SelectBitmap( hBmp );    
                memDC.SelectBitmap(hOldBmp);

                memDC.Detach();
                
            //cdc.Detach();
                dc.Detach();
                
                
            return TRUE;
            }


            BOOL CEnBitmap::StretchDraw(CDC 
            *pDC, LPRECT r, LPRECT sr )
            {
                
            if ( !r ) 
                    
            return FALSE;
                CDC dc;
                dc.CreateCompatibleDC( pDC
            ->m_hDC );
                HBITMAP hOldBitmap 
            = dc.SelectBitmap( m_hBitmap );
                pDC
            ->SetStretchBltMode(COLORONCOLOR);
                
                
            if ( !sr )
                    pDC
            ->StretchBlt( r->left, r->top, r->right, r->bottom, dc.m_hDC, 00, GetWidth(), GetHeight(), SRCCOPY );
                
            else
                    pDC
            ->StretchBlt( r->left, r->top, 
                    r
            ->right - r->left, 
                    r
            ->bottom - r->top, 
                    dc.m_hDC, 
                    sr
            ->left, 
                    sr
            ->top, 
                    sr
            ->right - sr->left, 
                    sr
            ->bottom - sr->top,
                    SRCCOPY );
                
                dc.SelectBitmap( hOldBitmap );
                
            if(dc.m_hDC) ::DeleteDC(dc.Detach());
                ::DeleteObject(hOldBitmap);
                hOldBitmap 
            = NULL;

                
            return TRUE;    
            }


            BOOL CEnBitmap::StretchDraw(CDC 
            *pDC, LPRECT r)
            {
                CDC dc;
                dc.CreateCompatibleDC( pDC
            ->m_hDC );
                HBITMAP bmp 
            = dc.SelectBitmap( m_hBitmap );
                
                pDC
            ->StretchBlt( r->left, r->top, r->right, r->bottom, dc.m_hDC, 00, GetWidth(), GetHeight(), SRCCOPY );
                
                dc.SelectBitmap( bmp );
                
            if(dc.m_hDC) ::DeleteDC(dc.Detach());
                ::DeleteObject(bmp);
                bmp 
            = NULL;

                
            return TRUE;    
            }


            BOOL CEnBitmap::Draw(CDC 
            *pDC, LPRECT r)
            {
                CDC dc;
                dc.CreateCompatibleDC( pDC
            ->m_hDC );
                HBITMAP bmp 
            = dc.SelectBitmap( m_hBitmap );    
                pDC
            ->BitBlt( r->left, r->top, r->right - r->left, r->bottom - r->top, dc.m_hDC, 00, SRCCOPY );
                
                dc.SelectBitmap( bmp );    
                ::DeleteDC(dc.Detach());

                
            return TRUE;
            }

            posted on 2008-01-17 22:02 深藍(lán)色系統(tǒng) 閱讀(1265) 評(píng)論(0)  編輯 收藏 引用 所屬分類: GDI/GDI+

            導(dǎo)航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統(tǒng)計(jì)

            常用鏈接

            留言簿(75)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            伊人久久大香线蕉综合热线| 97久久婷婷五月综合色d啪蜜芽 | 久久综合欧美成人| 久久久久久久免费视频| 色偷偷久久一区二区三区| 久久伊人中文无码| 91麻精品国产91久久久久| av无码久久久久不卡免费网站| 久久乐国产综合亚洲精品| 久久久久亚洲AV无码专区体验| 少妇内射兰兰久久| 奇米综合四色77777久久| 91超碰碰碰碰久久久久久综合| 伊人久久亚洲综合影院| 久久综合亚洲色一区二区三区| 麻豆精品久久久久久久99蜜桃| 国产精品一区二区久久| 久久久中文字幕| 中文字幕无码久久精品青草| 国产精品久久久久久久久免费| 成人免费网站久久久| 亚洲国产成人久久精品99| 精品一区二区久久| 精品久久久中文字幕人妻| 久久中文骚妇内射| 色综合久久天天综线观看| 久久久久亚洲AV无码专区首JN| 99久久国产热无码精品免费 | 久久中文娱乐网| 久久国产劲爆AV内射—百度| 久久99精品久久久久久噜噜| 久久久久久极精品久久久| 中文字幕无码久久精品青草| 青草影院天堂男人久久| 中文国产成人精品久久不卡| 久久久精品人妻无码专区不卡 | 精品久久久久久国产| 久久综合久久伊人| 国产高潮国产高潮久久久91| 欧美麻豆久久久久久中文| 91精品国产91久久久久久青草|