• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    CComboBox Ownerdraw combobox(skin)
    Last Modify : 27 December, 2010(01:52)
    // ComboBoxExk.cpp : implementation file
    //
    
    // DATE		: June 27, 2006
    // CODER	: Kurome (aucd29@gmail.com)
    //
    //
    // -----------------------------------------------------------------------
    // NOTE : July 28, 2006
    // -----------------------------------------------------------------
    // * 찾다가 못 찾아서 결국 내가 직접 만들게 되는 ComboBox -_-;
    //
    
    #include "stdafx.h"
    #include "SMS_WIZARD.h"
    #include "ComboBoxExk.h"
    #include "memdc.h"
    
    
    // CComboBoxExk
    
    IMPLEMENT_DYNAMIC(CComboBoxExk, CComboBox)
    
    CComboBoxExk::CComboBoxExk()
    : m_bFocus(false)
    , m_bClick(false)
    , m_szFont(_T("tahoma"))
    , m_nFontSize(13)
    , m_nNormalImage(0)
    , m_nOverImage(0)
    {
    	m_crBorder = RGB(0, 0, 0);
    }
    
    CComboBoxExk::~CComboBoxExk()
    {
    }
    
    
    BEGIN_MESSAGE_MAP(CComboBoxExk, CComboBox)
    	ON_WM_PAINT()
    	ON_WM_MOUSEMOVE()
    	ON_WM_LBUTTONDOWN()
    	ON_CONTROL_REFLECT(CBN_SELCHANGE, &CComboBoxExk::OnCbnSelchange)
    	ON_CONTROL_REFLECT(CBN_SELENDCANCEL, &CComboBoxExk::OnCbnSelendcancel)
    	ON_WM_ERASEBKGND()
    END_MESSAGE_MAP()
    
    
    
    // CComboBoxExk message handlers
    
    void CComboBoxExk::OnPaint()
    {
    	CPaintDC dc(this); // device context for painting
    	CRect rClient;	
    	GetClientRect(rClient);
    	CMemDC mDC(&dc, &rClient);
    	CDC bitmapDC;
    	bitmapDC.CreateCompatibleDC(&dc);
    	
    	CPen myPen, * pOldPen;
    	myPen.CreatePen(PS_SOLID, 1, m_crBorder);
    	pOldPen = mDC.SelectObject(&myPen);
    	mDC.Rectangle(&rClient);
    
    	CString szCurentText;
    	GetLBText(GetCurSel(), szCurentText);
    
    	if (szCurentText != L"")
    	{
    		CFont font;
    		LOGFONT lf;
    		memset(&lf, 0, sizeof(LOGFONT));
    		lf.lfHeight = m_nFontSize;
    		wsprintf(lf.lfFaceName, m_szFont);
    		font.CreateFontIndirect(&lf);
    		CFont* def_font = mDC.SelectObject(&font);
    		mDC.SetBkMode(TRANSPARENT);
    
    		// 선택한 데이터가 있으면 출력 해주자.
    		mDC.TextOut(4, 4, szCurentText);
    
    		mDC.SelectObject(def_font);
    		font.DeleteObject();
    	}
    
    	BITMAP bm;
    	CBitmap bmpButton;	
    	CBitmap bmpButtonOver;
    
    	// 이미지가 없으면 리턴.
    	if (!m_nNormalImage || ! m_nOverImage)
    	{
    		return;
    	}
    	
    	bmpButton.LoadBitmap(m_nNormalImage);
    	bmpButtonOver.LoadBitmap(IDB_BTN_COMBO_OVER);
    	bmpButton.GetObject(sizeof(BITMAP), &bm);
    
    	if(!m_bFocus)
    	{
    		bitmapDC.SelectObject(&bmpButtonOver);
    	}
    	else
    	{
    		bitmapDC.SelectObject(&bmpButton);
    	}
    
    	mDC.BitBlt((rClient.Width() - bm.bmWidth)-1, 1, bm.bmWidth, bm.bmHeight, &bitmapDC, 0, 0, SRCCOPY);
    	mDC.SelectObject(pOldPen);
    }
    
    void CComboBoxExk::SetBorderColor(COLORREF crBorder)
    {
    	m_crBorder = crBorder;
    }
    
    void CComboBoxExk::OnMouseMove(UINT nFlags, CPoint point)
    {
    	CRect rectClient;
    	GetClientRect(rectClient);
    
    	if (rectClient.PtInRect(point))
    	{
    		if (!m_bClick)
    		{	
    			if (!m_bFocus)
    			{
    				m_bFocus = true;
    				SetCapture();
    			}			
    		}
    	}
    	else
    	{
    		if(!m_bClick)
    		{
    			m_bClick = false;
    			m_bFocus = false;
    			ReleaseCapture();
    		}		
    	}
    
    	CComboBox::OnMouseMove(nFlags, point);
    }
    
    void CComboBoxExk::OnLButtonDown(UINT nFlags, CPoint point)
    {
    	// 클릭시 이미지변경을 위한 작업
    	m_bClick = true;
    	m_bFocus = false;
    	ReleaseCapture();
    
    	CComboBox::OnLButtonDown(nFlags, point);
    }
    
    void CComboBoxExk::OnCbnSelchange()
    {
    	// 아이템을 선택했을 때 클릭한 값을 반전
    	m_bClick = false;
    	Invalidate();
    }
    
    void CComboBoxExk::OnCbnSelendcancel()
    {
    	// 아이템을 클릭하지 않고 빠져 나갔을 때 클릭한 값을 반전
    	m_bClick = false;
    }
    
    void CComboBoxExk::SetFont(LPCTSTR szFont, int nFont)
    {
    	m_szFont	= szFont;
    	m_nFontSize = nFont;
    }
    
    BOOL CComboBoxExk::OnEraseBkgnd(CDC* pDC)
    {
    	return true;
    	//return CComboBox::OnEraseBkgnd(pDC);
    }
    
    void CComboBoxExk::SetImage(unsigned int nNormalImage, unsigned int nOverImage)
    {
    	m_nNormalImage	= nNormalImage;
    	m_nOverImage	= nOverImage;
    }
    

    Comment


    입력하3 1508232007



    Locations of visitors to this page