www.pudn.com > qiyehetongguanli.rar > BaseButton.cpp


// BaseButton.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "htglxt.h" 
#include "BaseButton.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CBaseButton 
 
CBaseButton::CBaseButton() 
{ 
 
} 
 
CBaseButton::~CBaseButton() 
{ 
	m_Down.DeleteObject(); 
	m_Up.DeleteObject(); 
	m_Enabled.DeleteObject(); 
	 
} 
 
 
BEGIN_MESSAGE_MAP(CBaseButton, CButton) 
	//{{AFX_MSG_MAP(CBaseButton) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBaseButton message handlers 
void CBaseButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)  
{ 
	CDC* pDC; 
	CDC memDC; 
	CBrush brush; 
	brush.CreateSolidBrush(RGB(255,255,255)); 
	pDC=CDC::FromHandle(lpDrawItemStruct->hDC); 
	UINT state=lpDrawItemStruct->itemState; 
	CRect rect=lpDrawItemStruct->rcItem; 
	//»­°´Å¥ 
	pDC->FillRect(rect,&brush); 
	memDC.CreateCompatibleDC(pDC); 
	if(state&ODS_SELECTED) 
	{ 
		memDC.SelectObject(m_Up); 
		pDC->SetTextColor(RGB(219,147,132)); 
	} 
	else 
	{ 
		memDC.SelectObject(m_Down); 
		pDC->SetTextColor(RGB(44,102,153)); 
	} 
	if(state&ODS_DISABLED) 
	{ 
		memDC.SelectObject(m_Enabled); 
		pDC->SetTextColor(RGB(128,128,128)); 
	} 
	BITMAP bitstruct; 
	m_Up.GetBitmap(&bitstruct); 
	pDC->BitBlt((rect.Width()/2)-(bitstruct.bmWidth/2),0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY); 
	//д°´Å¥Îı¾ 
	pDC->SetBkMode(TRANSPARENT); 
	CString sCaption; 
 
	this->GetWindowText(sCaption); 
	pDC->DrawText(sCaption,rect,DT_CENTER|DT_BOTTOM|DT_SINGLELINE); 
	memDC.DeleteDC(); 
	brush.DeleteObject(); 
} 
 
 
BOOL CBaseButton::PreTranslateMessage(MSG* pMsg)  
{ 
 
	if(pMsg->hwnd==this->GetSafeHwnd()&&pMsg->message==WM_KEYDOWN && pMsg->wParam==13) 
	{ 
		pMsg->lParam=589857; 
		pMsg->message=WM_LBUTTONDOWN; 
	} 
	if(pMsg->hwnd==this->GetSafeHwnd()&&pMsg->message==WM_KEYUP && pMsg->wParam==13) 
	{ 
		pMsg->lParam=589857; 
		pMsg->message=WM_LBUTTONUP; 
	} 
 
	return CButton::PreTranslateMessage(pMsg); 
} 
 
 
void CBaseButton::LoadPic(UINT downpic, UINT uppic, UINT enabledpic) 
{ 
	if(downpic==NULL||uppic==NULL||enabledpic==NULL) 
		return; 
	m_Down.LoadBitmap(downpic); 
	m_Up.LoadBitmap(uppic); 
	m_Enabled.LoadBitmap(enabledpic); 
 
}