Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing the toolbar

Changing the toolbar

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestionlearning
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rand Althor
    wrote on last edited by
    #1

    Hi, I'm creating an app with single document but multiple views. I'm trying to dynamically change the toolbar as different views are activated. At the moment, I overwrite the ActivateView() function of each view to make a call to the following function: BOOL CMainFrame::SetupMainFrameToolbar(UINT ToolbarResourceID, BOOL loadToolbar/* = TRUE */) { // Load the toolbar as necessary if (loadToolbar == TRUE) { if (!m_wndToolBar.LoadToolBar(ToolbarResourceID)) { TRACE0("Failed to create toolbar\n"); return (FALSE); } } int tempID, location; CString stringToDisplay, tempString; // Loop through all of the buttons of the toolbar UINT ButtonCounter = m_wndToolBar.GetCount(); for (int index = 0; index < ButtonCounter; index++) { // Get the command ID of the button tempID = m_wndToolBar.GetItemID (index); // Get the string resource associated with that command ID tempString.LoadString(tempID); // Find the last string in that resource location = tempString.GetLength() - tempString.ReverseFind ('\n') - 1; // Cut it and set as the button's title stringToDisplay = tempString.Right (location); m_wndToolBar.SetButtonText (index, _T((LPCTSTR) stringToDisplay)); } // change the toolbar size to accomodate the text m_wndToolBar.SetSizes (TOOLBAR_BUTTON_SIZE, TOOLBAR_BUTTON_IMAGE_SIZE); if (loadToolbar == TRUE) { // Float and redock this toolbar to recalculate sizes FloatControlBar(&(m_wndToolBar), CPoint(50,50)); DockControlBar (&(m_wndToolBar), AFX_IDW_DOCKBAR_TOP); } // Recalculate the main frame's layout to position the toolbar appropriately. RecalcLayout(); // Invalidate the window containing the toolbar so it gets redrawn m_wndToolBar.InvalidateRect (NULL, TRUE); // done correctly return (TRUE); } As you can see, I was forced to float and redock the toolbar, as AutoSize() doesn't work (it clips my new toolbar to the width of the old toolbar) and RecalcLayout() makes my toolbar buggy (text is only displayed after first a mouse has hovered over the toolbar). Anybody has ever done this before? Like totally replace the main toolbar everytime a new view is activated? Help ^^ :-D

    R 1 Reply Last reply
    0
    • R Rand Althor

      Hi, I'm creating an app with single document but multiple views. I'm trying to dynamically change the toolbar as different views are activated. At the moment, I overwrite the ActivateView() function of each view to make a call to the following function: BOOL CMainFrame::SetupMainFrameToolbar(UINT ToolbarResourceID, BOOL loadToolbar/* = TRUE */) { // Load the toolbar as necessary if (loadToolbar == TRUE) { if (!m_wndToolBar.LoadToolBar(ToolbarResourceID)) { TRACE0("Failed to create toolbar\n"); return (FALSE); } } int tempID, location; CString stringToDisplay, tempString; // Loop through all of the buttons of the toolbar UINT ButtonCounter = m_wndToolBar.GetCount(); for (int index = 0; index < ButtonCounter; index++) { // Get the command ID of the button tempID = m_wndToolBar.GetItemID (index); // Get the string resource associated with that command ID tempString.LoadString(tempID); // Find the last string in that resource location = tempString.GetLength() - tempString.ReverseFind ('\n') - 1; // Cut it and set as the button's title stringToDisplay = tempString.Right (location); m_wndToolBar.SetButtonText (index, _T((LPCTSTR) stringToDisplay)); } // change the toolbar size to accomodate the text m_wndToolBar.SetSizes (TOOLBAR_BUTTON_SIZE, TOOLBAR_BUTTON_IMAGE_SIZE); if (loadToolbar == TRUE) { // Float and redock this toolbar to recalculate sizes FloatControlBar(&(m_wndToolBar), CPoint(50,50)); DockControlBar (&(m_wndToolBar), AFX_IDW_DOCKBAR_TOP); } // Recalculate the main frame's layout to position the toolbar appropriately. RecalcLayout(); // Invalidate the window containing the toolbar so it gets redrawn m_wndToolBar.InvalidateRect (NULL, TRUE); // done correctly return (TRUE); } As you can see, I was forced to float and redock the toolbar, as AutoSize() doesn't work (it clips my new toolbar to the width of the old toolbar) and RecalcLayout() makes my toolbar buggy (text is only displayed after first a mouse has hovered over the toolbar). Anybody has ever done this before? Like totally replace the main toolbar everytime a new view is activated? Help ^^ :-D

      R Offline
      R Offline
      Rand Althor
      wrote on last edited by
      #2

      Again, no reply.. and again, I've solved the problem ^^ What I do is I create an array of toolbars in my MainFrame, and turn them on and off and redock them as the need arise. Okay.. thanks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups