www.pudn.com > CToolBarEx.rar > ToolBarEx.cpp


// ToolBarEx.cpp : implementation file 
// 
//Author:xiaojin 
//Nanjing BC Foods Co. Limited 
//E-mail:xiaoj@njb.swirebev.com 
//Tel:025-8642091 
//Date:04-30-2003 
 
#include "stdafx.h" 
#include "TB.h" 
#include "ToolBarEx.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CToolBarEx 
 
CToolBarEx::CToolBarEx() 
{ 
	sizeImage.cx =20; 
	sizeImage.cy =20; 
	img.Create(sizeImage.cx-1, sizeImage.cy-1, ILC_COLOR8|ILC_MASK, 1,1); 
} 
 
CToolBarEx::~CToolBarEx() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CToolBarEx, CToolBar) 
//{{AFX_MSG_MAP(CToolBarEx) 
// NOTE - the ClassWizard will add and remove mapping macros here. 
//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CToolBarEx message handlers 
 
void CToolBarEx::SetImage() 
{ 
	this->GetToolBarCtrl().SetImageList (&img); 
} 
 
void CToolBarEx::SetButtonNumber(int n) 
{ 
    SetButtons(NULL,n); 
} 
 
void CToolBarEx::SetButton(int nButton, int nID, int nImage,LPTSTR lpText) 
{ 
    SetButtonInfo(nButton, nID, TBSTYLE_BUTTON, nImage); 
	SetButtonText(nButton, lpText);	 
} 
 
void CToolBarEx::SetButton(int nButton, int nID, int nImage) 
{ 
    SetButtonInfo(nButton, nID, TBSTYLE_BUTTON, nImage); 
} 
 
void CToolBarEx::SetSize(int nWidth,int nHeight) 
{ 
    CSize cs; 
	cs.cx =nWidth; 
	cs.cy =nHeight; 
	SetSizes(cs, sizeImage); 
} 
 
void CToolBarEx::AddIcon(HICON hIcon) 
{ 
	img.Add (hIcon); 
} 
 
 
void CToolBarEx::AddSeparator(int nButton) 
{ 
	SetButtonInfo(nButton, 0, TBBS_SEPARATOR, 0); 
} 
 
void CToolBarEx::SetDefaultSize() 
{ 
	CRect rectToolBar; 
	//得到按钮的大小 
	GetItemRect(0, &rectToolBar); 
	//设置按钮的大小 
	SetSizes(rectToolBar.Size (), sizeImage); 
} 
 
void CToolBarEx::AddBitmap(CBitmap *pbmImage, CBitmap *pbmMask) 
{ 
	img.Add( pbmImage, pbmMask); 
} 
 
void CToolBarEx::AddBitmap(CBitmap *pbmImage, COLORREF crMask) 
{ 
	img.Add( pbmImage, crMask); 
} 
 
void CToolBarEx::SetImageSize(int nImageWidth,int nImageHeight) 
{ 
   sizeImage.cx = nImageWidth; 
   sizeImage.cy =nImageHeight; 
}