www.pudn.com > PressMonitor_q.zip > MainToolBar.cpp
// MainToolBar.cpp : implementation file
//
#include "stdafx.h"
#include "Monitor.h"
#include "MainToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainToolBar
CMainToolBar::CMainToolBar()
{
}
CMainToolBar::~CMainToolBar()
{
}
BEGIN_MESSAGE_MAP(CMainToolBar, CToolBar)
//{{AFX_MSG_MAP(CMainToolBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainToolBar message handlers
BOOL CMainToolBar::LoadToolBar(UINT nIDResource)
{
BOOL bReturn=CToolBar::LoadToolBar(nIDResource);
//Check if we loaded the toolbar
if(bReturn==FALSE)
return bReturn;
//Make it flat
ModifyStyle(0,GetStyle()|TBSTYLE_FLAT);
//Set the text for each button
CToolBarCtrl&bar=GetToolBarCtrl();
//Remove the string map in case we are loading
//another toolbar into this control
if(m_pStringMap)
{
delete m_pStringMap;
m_pStringMap=NULL;
}
int nIndex=0;
TBBUTTON tb;
for(nIndex=bar.GetButtonCount()-1;nIndex>=0;nIndex--)
{
ZeroMemory(&tb,sizeof(TBBUTTON));
bar.GetButton(nIndex,&tb);
//Do we have a separator?
if((tb.fsStyle&TBSTYLE_SEP)==TBSTYLE_SEP)
continue;
//Have we got a valid command id?
if(tb.idCommand==0)
continue;
//Get the resource string if there is one.
CString strText;
LPCTSTR lpszButtonText=NULL;
CString strButtonText(_T(""));
_TCHAR seps[]=_T("\n");
strText.LoadString(tb.idCommand);
if(!strText.IsEmpty())
{
lpszButtonText=_tcstok((LPTSTR)(LPCTSTR)strText,seps);
while(lpszButtonText)
{
strButtonText=lpszButtonText;
lpszButtonText=_tcstok(NULL,seps);
}
}
if(!strButtonText.IsEmpty())
SetButtonText(nIndex,strButtonText);
}
//Resize the button so that the text will fit
CRect rc(0,0,0,0);
CSize sizeMax(0,0);
for(nIndex=bar.GetButtonCount()-1;nIndex>=0;nIndex--)
{
bar.GetItemRect(nIndex,rc);
rc.NormalizeRect();
sizeMax.cx=__max(rc.Size().cx,sizeMax.cx);
sizeMax.cy=__max(rc.Size().cy,sizeMax.cy);
}
SetSizes(sizeMax,CSize(16,15));
return bReturn;
}