Search code examples
windowsvisual-c++mfccommon-controls

How to attach a band to the right side of CReBar control


On my frame window I have a CReBar control with non-movable bands on several lines. On the last line there are two bands, which currently aligned to the left, the second immediately after the first.

+--------+-------+------------------------------------+
|11111111|2222222|
+--------+-------+------------------------------------+

But my product management wants me to attach the second band to the right side of the line, with empty space in the middle.

+--------+------------------------------------+-------+
|11111111|                                    |2222222|
+--------+------------------------------------+-------+

I cannot find anywhere how to do that. I would be grateful for any help.

Edit: The actual code uses the Xtreme GUI library, but its structure is pretty standard:

// ... Create toolbars
// Add toolbars to ReBar.
if (m_wndReBar.Create(this) &&
    m_wndReBar.AddToolBar(pNavigateTB, RBBS_BREAK | RBBS_NOGRIPPER) &&
    m_wndReBar.AddBar(&m_wndAddressBar, NULL, NULL, RBBS_NOGRIPPER) &&
    m_wndReBar.AddToolBar(pMainToolBar, RBBS_BREAK | RBBS_NOGRIPPER) &&
    m_wndReBar.AddToolBar(pViewsHelpTB, RBBS_NOGRIPPER))
{
    ...
}

Here m_wndReBar is a CReBar-derived class, and toolbars are Xtreme wrappers of the common Toolbar control. They use the regular MFC flags, and I didn't find an option to align toolbar to the right.


Solution

  • There is no style or parameter of a toolbar, which forces it to align to the right. However, it is possible to expand the previous toolbar in a way that it will push the subsequent toolbar to the rightmost position.

    Let, as in the first figure above, two consecutive toolbars are on the same line in the CReBar, and the first toolbar has index I. Than the command

    m_ReBar.SendMessage(RB_MAXIMIZEBAND, I, 0);
    

    will move the second toolbar to the right, as in the second figure. This rightmost position will be kept during the window resizing, but adding a new toolbar to the rebar can break it.