Code to Dynamically Redock a Toolbar at Runtime

This is a simple code snippet that enables you to dyamically enable docking and then dock any toolbar at runtime. To use (or test) this code, simply add the following code to a COMMAND message handler such as OnChangeToolBar and the code will allow you to re-dock any undocked toolbars. Obviously, one way of implementing this would be to have a function that allows novice end-users that get happy with their mice to reset, or redock all toolbars at once. In that case, you could simply keep the toolbar ids in an array and iterate through them, redocking each one.
void CMainFrame::OnChangeToolBar() 
{
 if(!m_wndToolBar.LoadToolBar(IDR_NEWTOOLBAR))
  AfxMessageBox("Error: could not load toolbar");

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


Comments

  • Docking to a specific location?

    Posted by Legacy on 09/15/2003 12:00am

    Originally posted by: Jon

    Okay, I can dock my (3) toolbars to the top of my window, but they always appear on three seperatre lines - one above the other. There must be a way to force them all onto the same line... but what is it?

    [edit]Just found the answer :) http://www.codeguru.com/toolbar/demo_toolbar_d.shtml[/edit]

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

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds