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

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);
}

转载自:https://blog.csdn.net/confach/article/details/34337

You may also like...

退出移动版