• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    CStaticExBitmap
    Last Modify : 27 December, 2010(02:44)
    // DATE		: February 27, 2007
    // CODER	: Kurome (aucd29@gmail.com)
    // VERSION	: 1.0
    //
    //
    // Require
    // ----------------------------------------------------------
    // CStaticEx
    // http://www.sarangnamu.net/basic/basic_view.php?no=2844
    //
    // ----------------------------------------------------------
    // CImageLoader
    // http://www.sarangnamu.net/basic/basic_view.php?no=2839
    //
    
    #include "StdAfx.h"
    #include "StaticExBitmap.h"
    #include "Main Unit Manager.h"
    
    CStaticExBitmap::CStaticExBitmap(void)
    : m_pbmpOne(NULL)
    , m_pStretchPos(NULL)
    , m_bBitmapSet(false)
    {
    	m_pbmp[_LEFT]	= NULL;
    	m_pbmp[_CENTER]	= NULL;
    	m_pbmp[_RIGHT]	= NULL;
    	m_nAlign		= DT_CENTER | DT_VCENTER | DT_SINGLELINE ;	
    }
    
    CStaticExBitmap::~CStaticExBitmap(void)
    {
    	if (m_pbmp[_LEFT])
    	{
    		delete m_pStretchPos;
    	}
    }
    
    BEGIN_MESSAGE_MAP(CStaticExBitmap, CStaticEx)
    	ON_WM_PAINT()
    END_MESSAGE_MAP()
    
    void CStaticExBitmap::InitObject(CDC* pDC)
    {
    	CStaticEx::InitObject(pDC);	
    
    	if (!m_bBitmapSet)
    	{
    		if (m_pbmpOne)
    		{
    			BITMAP bm;
    
    			m_pbmpOne->GetObject(sizeof(BITMAP), &bm);
    
    			// rect의 크기를 bitmap 사이즈로 변경한다.
    			m_rect.right  = bm.bmWidth;
    			m_rect.bottom = bm.bmHeight;
    		}
    		else if (m_pbmp[_LEFT])
    		{
    			m_pbmp[_LEFT]->GetObject(sizeof(BITMAP), &bm[_LEFT]);
    			m_pbmp[_CENTER]->GetObject(sizeof(BITMAP), &bm[_CENTER]);
    			m_pbmp[_RIGHT]->GetObject(sizeof(BITMAP), &bm[_RIGHT]);
    
    			m_pStretchPos = new CStretchPos;
    			m_dcBuff.CreateCompatibleDC(pDC);
    
    			m_pStretchPos->nCenterLX = m_rect.Width() - bm[_LEFT].bmWidth - bm[_RIGHT].bmWidth;
    			m_pStretchPos->nRightPos = m_rect.Width() - bm[_RIGHT].bmWidth;
    
    			// fix rect
    			m_rect.bottom = bm[_LEFT].bmHeight;
    		}
    
    		m_bBitmapSet = true;
    	}
    }
    
    void CStaticExBitmap::OnPaint()
    {
    	CPaintDC dc(this); // device context for painting
    	
    	InitObject(&dc);
    		
    	if (m_pbmpOne)
    	{
    		mDC.SelectObject(m_pbmpOne);
    		mDC.BitBlt(0, 0, m_rect.Width(), m_rect.Height(), &mDC, 0, 0, SRCCOPY);
    	}
    	else if (m_pbmp[_LEFT])
    	{
    		m_dcBuff.SelectObject(m_pbmp[_LEFT]);
    		mDC.BitBlt(0, 0, bm[_LEFT].bmWidth, bm[_LEFT].bmHeight, &m_dcBuff, 0, 0, SRCCOPY);
    
    		m_dcBuff.SelectObject(m_pbmp[_CENTER]);
    		mDC.StretchBlt(bm[_LEFT].bmWidth, 0, m_pStretchPos->nCenterLX, bm[_LEFT].bmHeight, &m_dcBuff, 0, 0, bm[_CENTER].bmWidth, bm[_CENTER].bmHeight, SRCCOPY);
    		
    		m_dcBuff.SelectObject(m_pbmp[_RIGHT]);
    		mDC.BitBlt(m_pStretchPos->nRightPos, 0, bm[_RIGHT].bmWidth, bm[_LEFT].bmHeight, &m_dcBuff, 0, 0, SRCCOPY);
    	}
    	
    	mDC.DrawText(m_szWindowText,m_rect,m_nAlign);
    	dc.BitBlt(0, 0, m_rect.Width(), m_rect.Height(), &mDC, 0, 0, SRCCOPY);
    	DeleteObject();
    }
    
    void CStaticExBitmap::AttachBitmap(CBitmap* pBitmap)
    {
    	m_pbmpOne = pBitmap;
    }
    
    void CStaticExBitmap::AttachBitmap(CImageData* pImg)
    {
    	// 이렇게 받은건 공통적으로 사용하기 위해서 3부분 컷팅했을 경우
    	int i;
    
    	for (i=0; i<pImg->m_nLength; ++i)
    	{
    		m_pbmp[i] = pImg->m_pBmp[i];
    	}
    }
    
    #pragma once
    
    #include "StaticEx.h"
    #include "ImageLoader.h"
    
    enum BitmapPos
    {
    	_LEFT = 0,
    	_CENTER,
    	_RIGHT
    };
    
    class CStretchPos
    {
    public:
    	int nCenterLX, nRightPos;
    };
    
    class CStaticExBitmap :
    	public CStaticEx
    {
    public:
    	CStaticExBitmap(void);
    	~CStaticExBitmap(void);
    
    protected:
    	virtual void InitObject(CDC* pDC);
    	DECLARE_MESSAGE_MAP()
    
    protected:
    	afx_msg void OnPaint();
    
    protected:
    	CDC m_dcBuff;
    	bool m_bBitmapSet;
    	BITMAP bm[3];
    	CBitmap* m_pbmp[3], * m_pbmpOne;
    	CStretchPos* m_pStretchPos;
    	
    public:
    	void AttachBitmap(CBitmap* pBitmap);
    	void AttachBitmap(CImageData* pImg);
    };
    

    Comment


    입력하3 1508772425



    Locations of visitors to this page