BmpButton.cpp
资源名称:src.zip [点击查看]
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:2k
源码类别:
ICQ/即时通讯
开发平台:
Visual C++
- // BmpButton.cpp : implementation file
- //
- #include "stdafx.h"
- #include "BmpButton.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CBmpButton
- CBmpButton::CBmpButton()
- {
- }
- CBmpButton::~CBmpButton()
- {
- }
- BEGIN_MESSAGE_MAP(CBmpButton, CButton)
- //{{AFX_MSG_MAP(CBmpButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CBmpButton message handlers
- void CBmpButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- if(m_bitmap.GetObject==NULL)
- return;
- UINT nOffset=0;
- UINT nFrameStyle=0;
- BOOL bDRAWFOCUSONLY = FALSE;
- int nState=lpDrawItemStruct->itemState;
- UINT nNewAction = lpDrawItemStruct->itemAction;
- if ( nState & ODS_SELECTED)
- {
- nFrameStyle = DFCS_PUSHED;
- nOffset += 1;
- }
- nState=DSS_NORMAL;
- if (nNewAction == ODA_FOCUS )
- bDRAWFOCUSONLY = TRUE;
- CRect rt;
- GetClientRect(&rt);
- if(!bDRAWFOCUSONLY)
- {
- CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
- CRect rtControl( lpDrawItemStruct->rcItem );
- CPoint pt(rtControl.left,rtControl.top);
- CSize sizeDraw;
- sizeDraw.cx=rt.Width();
- sizeDraw.cy=rt.Height();
- pt.Offset(nOffset,nOffset);
- pDC->Rectangle( &lpDrawItemStruct->rcItem );
- pDC->DrawFrameControl(&rtControl, DFC_BUTTON, DFCS_BUTTONPUSH | nFrameStyle);
- pDC->DrawState(pt,sizeDraw,m_bitmap,DST_BITMAP|nState);
- }
- }
- void CBmpButton::SetBitmap(CBitmap *pBit)
- {
- CRect rt;
- GetClientRect(&rt);
- m_bitmap.DeleteObject();
- HBITMAP hb=(HBITMAP)::CopyImage(pBit->GetSafeHandle(),IMAGE_BITMAP,rt.Width(),rt.Height(),LR_CREATEDIBSECTION);
- m_bitmap.Attach(hb);
- Invalidate();
- }