CSDN博客

img confach

如何在工具栏中,加上图标和文字?(How To Add Icon And Text)

发表于2004/7/5 14:51:00  1088人阅读

分类: VC

a).如何在工具栏中,加上图标和文字?(How To Add Icon And Text)

/********************************************************************/
/* */
/* Function name : CreateHotToolBar */
/* Description : Create the main toolbar. */
/* */
/********************************************************************/
BOOL CMainFrame::CreateHotToolBar()
{
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC/*| CBRS_GRIPPER*/) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar/n");
return FALSE; // fail to create
}

// Set the text for each button
CToolBarCtrl& bar = m_wndToolBar.GetToolBarCtrl();

int nIndex = 0;
TBBUTTON tb;

for (nIndex = m_wndToolBar.GetToolBarCtrl().GetButtonCount() - 1; nIndex >= 0; nIndex--)
{
ZeroMemory(&tb, sizeof(TBBUTTON));
m_wndToolBar.GetToolBarCtrl().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())
m_wndToolBar.SetButtonText(nIndex, strButtonText);
}

0 0

相关博文

我的热门文章

img
取 消
img