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

📄 texttoolbar.cpp

📁 民航机票预订系统 结合MFC界面编程 具有订票、退票
💻 CPP
字号:
// TextToolBar.cpp : implementation file
//

#include "stdafx.h"
#include "TextToolBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTextToolBar

CTextToolBar::CTextToolBar()
{
}

CTextToolBar::~CTextToolBar()
{
}


BEGIN_MESSAGE_MAP(CTextToolBar, CToolBar)
	//{{AFX_MSG_MAP(CTextToolBar)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTextToolBar message handlers
BOOL CTextToolBar::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);
      //  strText="ASD";
		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 buttons 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;
}

⌨️ 快捷键说明

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