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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is there a way to move the right-most button of a CMFCToolbar to the right most position (of the rect) ?

Is there a way to move the right-most button of a CMFCToolbar to the right most position (of the rect) ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
3 Posts 2 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.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    Based on the "Visual C++ 2008 Feature Pack" sample VisualStudioDemo I have a toolbar (CMFCToolbar) in a docking pane (CDockPane) that contains operations to be done on the content of the docking pane. Currently, all the toolbar buttons are "aligned" from the left side; as it is expected when working with a toolbar. Is there a way to move the right-most button in the toolbar to be at the right-most side or the rect (of the toobar) ? for example ( in ascii art) to have something like this (toolbar is between [] )

    ==================================================
    | \[button1|button2|button3|             button4\] |
    |------------------------------------------------|
    |                                                |
    

    The toolbar rect spans the whole width of the docking pane (also resizes when the docking pane resizes) Looking at the CMFCToolbar documentation and code (afxtoolbar.cpp/.h) does not seem to offer some API to do that. So, Am I chasing a wild goose? Thanks. Max.

    I'd rather be phishing!

    E 1 Reply Last reply
    0
    • M Maximilien

      Based on the "Visual C++ 2008 Feature Pack" sample VisualStudioDemo I have a toolbar (CMFCToolbar) in a docking pane (CDockPane) that contains operations to be done on the content of the docking pane. Currently, all the toolbar buttons are "aligned" from the left side; as it is expected when working with a toolbar. Is there a way to move the right-most button in the toolbar to be at the right-most side or the rect (of the toobar) ? for example ( in ascii art) to have something like this (toolbar is between [] )

      ==================================================
      | \[button1|button2|button3|             button4\] |
      |------------------------------------------------|
      |                                                |
      

      The toolbar rect spans the whole width of the docking pane (also resizes when the docking pane resizes) Looking at the CMFCToolbar documentation and code (afxtoolbar.cpp/.h) does not seem to offer some API to do that. So, Am I chasing a wild goose? Thanks. Max.

      I'd rather be phishing!

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Yes, of course... :)

      // CYourToolBar : public CMfcToolBar

      /*virtual*/ void CYourToolBar::AdjustLocations()
      {
      __super::AdjustLocations();

      if (GetSafeHwnd())
      {
      int iCount(GetCount());
      if (iCount)
      {
      CRect crClient(0, 0, 0, 0);
      GetClientRect(crClient);

        CMFCToolBarButton\* pcButton(GetButton(iCount - 1));
        if (pcButton)
        {
          CRect crPos(pcButton->Rect());
          if (crClient.right > crPos.right)
          {
            crPos.OffsetRect(crClient.right - crPos.right, 0);
            pcButton->SetRect(crPos);
            UpdateTooltips();
          }
        }
      }
      

      }
      }

      They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

      M 1 Reply Last reply
      0
      • E Eugen Podsypalnikov

        Yes, of course... :)

        // CYourToolBar : public CMfcToolBar

        /*virtual*/ void CYourToolBar::AdjustLocations()
        {
        __super::AdjustLocations();

        if (GetSafeHwnd())
        {
        int iCount(GetCount());
        if (iCount)
        {
        CRect crClient(0, 0, 0, 0);
        GetClientRect(crClient);

          CMFCToolBarButton\* pcButton(GetButton(iCount - 1));
          if (pcButton)
          {
            CRect crPos(pcButton->Rect());
            if (crClient.right > crPos.right)
            {
              crPos.OffsetRect(crClient.right - crPos.right, 0);
              pcButton->SetRect(crPos);
              UpdateTooltips();
            }
          }
        }
        

        }
        }

        They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        Excellent !!! plug the code right in and works nearly ok; I have some minoe redraw issue that should be easy to track down. :thumbsup: Thanks.

        I'd rather be phishing!

        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