Joao Paulo Figueira (joao.fig@mail.telepac.pt), January 21, 2004.
Toolbar buttons are always inserted from the left to the right. How can I insert buttons that are right aligned?
After you've seen it working, it is actually quite simple. All we need to do is to insert an empty filler toolbar button with the appropriate size, so that all buttons to its right will be right-aligned.
To illustrate this technique, I've derived a class from CCeCommandBar that enables this functionality. To use it (check the sample application), load all the buttons in the command bar and call RightAlign using the ID of the first button you want to right-align. All the buttons to its right will be right-aligned.
The RightAlign method works by inserting an inactive button to the left of the button group you want to right-align. Next, its size is calculated and set so that the button group is moved to the right of the command bar.
This sample shows how to handle the SIP button, in case it is visible (most of the time). This button will overlap with the command bar, so you must adjust its size, otherwise the rightmost button will be hidden.
Finally, this code can be easily adapted to a CToolBar-derived class: just remove the SIP logic!
And that's it.
You can download a sample here - RightAlign.zip (33K).