Export (0) Print
Expand All

CToolBar::GetToolBarCtrl

This member function allows direct access to the underlying common control.

CToolBarCtrl& GetToolBarCtrl( ) const;

Return Value

A reference to a CToolBarCtrl object.

Remarks

Use GetToolBarCtrl to take advantage of the functionality of the Windows toolbar common control, and to take advantage of the support CToolBarCtrl provides for toolbar customization.

For more information about using common controls, see the article Controls and Common Controls in the Platform SDK.

Example

//This example shows how to add text to toolbar buttons.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
      return -1;

   //Create a toolbar. Resource ID of the toolbar to be loaded 
   //is IDR_MAINFRAME.

   if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE 
      | CBRS_TOP) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
   {
      TRACE0("Failed to create toolbar\n");
      return -1;      // fail to create
   }
   
   //Show text on toolbar buttons.
   VERIFY(m_wndToolBar.SetButtonText(0,"New"));
   VERIFY(m_wndToolBar.SetButtonText(1,"Open"));
   VERIFY(m_wndToolBar.SetButtonText(2,"Save"));
   VERIFY(m_wndToolBar.SetButtonText(4,"Cut"));
   VERIFY(m_wndToolBar.SetButtonText(5,"Copy"));
   VERIFY(m_wndToolBar.SetButtonText(6,"Paste"));
   VERIFY(m_wndToolBar.SetButtonText(8,"Print"));
   VERIFY(m_wndToolBar.SetButtonText(9,"About"));

   CRect temp;
   m_wndToolBar.GetItemRect(0,&temp);
   m_wndToolBar.GetToolBarCtrl()->SetButtonSize(CSize(temp.Width(),
      temp.Height()),CSize(16,15));

   return 0;
}

See Also

CToolBar Overview | Class Members | Hierarchy Chart | CToolBarCtrl

Show:
© 2014 Microsoft