⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmpbutton.cpp

📁 仿QQ的聊天程序vc++/mfc来学习的简易聊天室代码功能较全
💻 CPP
字号:
// 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();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -