Adding Text to a Docking Toolbar

Environment: VC6

This article demonstrates an easy way to add text to a docking tool bar. I was needed to add text to the toolbar for my dBase Explorer project (visit my web site for detail information: http://www.codearchive.com/~dbase). Although, I found some of the articles on it in the code projects/guru sites. Most of them are difficult to implement, and need to add a lot of coding or even a new class. Finally, I found the easy way to add text to a toolbar. So I would like to share it with the rest of the world. This article shows how you can add text to a toolbar only by adding a few lines of code. In order to add texts to a toolbar, you need to declare a member variables type CToolBar to the CMainFrame class as shown below:

// Any source code blocks look like this
class CMainFrame : public CFrameWnd
{
	
protected: // create from serialization only
    CMainFrame();
    DECLARE_DYNCREATE(CMainFrame)

protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;

...
};

If you use App Wizard to create your application, the member variable will be declared for you. So do you do not need to declared it by yourself. However, you have to call SetButtonText function with two parameters, first one is index of the icon, and the second one is the actual text. The actual text will appear just below the icon. The index start from 0. Each separator has also an index. So you have to count that too. The program listing below shows the index of each icon and also the text for each icon. The complete listing of OnCreate function is given below:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
      return -1;
	
   if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | 
         WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | 
         CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
   {
      TRACE0("Failed to create toolbar\n");
      return -1;      // fail to create
   }

   if (!m_wndStatusBar.Create(this) ||
      !m_wndStatusBar.SetIndicators(indicators,
         sizeof(indicators)/sizeof(UINT)))
   {
      TRACE0("Failed to create status bar\n");
      return -1;      // fail to create
   }

    m_wndToolBar.SetButtonText(0,"New");
    m_wndToolBar.SetButtonText(1,"Open");
    m_wndToolBar.SetButtonText(2,"Save");
    m_wndToolBar.SetButtonText(4,"Cut");
    m_wndToolBar.SetButtonText(5,"Copy");
    m_wndToolBar.SetButtonText(6,"Paste");
    m_wndToolBar.SetButtonText(8,"Print");
    m_wndToolBar.SetButtonText(10,"About");
    m_wndToolBar.SetSizes(CSize(42,38),CSize(16,15));


    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);

    return 0;

About the Author: Zahirul Haque started his software development career using C/C++ on Unix at Siemens Austria in 1991. In 1993, the author left Vienna and moved to Canada as an immigrant. Since then he has been working in various Canadian companies using C, C++, Java, Pro*C, SQL, PL/SQL, JavaScript, ASP (Active Server Pages), Oracle Designer/2000, Developer/2000, Oracle 7/8/8i, Microsoft Access Database, Codebase, xBase database, XVT Tools, Open Interface, Unix, X-Windows, Windows NT, Windows 3.1/95/98 etc. He is currently developing a xBase/dBase database tool called "dBase Explorer". dBase Explorer can be used to view data as well as all information including columns, version etc. of any dBase file. The demo version of this tool can be downloaded from his personal web site : http://www.codearchive.com/~dbase He is willing to take any contact software development project.

Downloads

Download demo project - 18 Kb
Download source - 3 Kb


Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds