Codejock Forums Homepage
Forum Home Forum Home > General > Articles and Tutorials
  New Posts New Posts RSS Feed - How to create a fixed toolbar
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to create a fixed toolbar

 Post Reply Post Reply
Author
Message
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Topic: How to create a fixed toolbar
    Posted: 05 June 2010 at 8:13pm
Hello

I wanted to create a toolbar that is neither movable, nor floatable nor closeable by the user.
I used the sample "GUI_VisualStudio".

What I wanted was a toolbar like this:



To achieve that remove all the code from CMainFrame::OnCreate() that contains pCommandBar.



Insert this code into the header file MainFrm.h:

    CXTPToolBar* mp_MainToolBar;



Insert this code into the file MainFrm.cpp:

    CXTPCommandBars* pCommandBars = GetCommandBars();

    mpMainToolBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
    if (!mp_MainToolBar || !mp_MainToolBar->LoadToolBar(IDR_MAINFRAME))
        return -1;

    // disallow floating
    mp_MainToolBar->SetFlags(0, xtpFlagFloating|xtpFlagAlignTop|xtpFlagAlignLeft|xtpFlagAlignRight|xtpFlagAlignBottom);

    // remove the menu that appears when right clicking the toolbar
    mp_MainToolBar->SetContextMenuPresent(FALSE);

    // avoid that the toolbar can be closed
    mp_MainToolBar->SetCloseable(FALSE);

    // remove gripper at the left side
    mp_MainToolBar->SetShowGripper(FALSE);

    // remove the drop down menu at the right side
    mp_MainToolBar->ShowExpandButton(FALSE);

    // if you like the text below the icon instead of a tooltip (optional)
//    mp_MainToolBar->ShowTextBelowIcons(TRUE);


That's it !

2.)

If you want additionally that the toolbar has 100% width of the window, add this to the header file:

    //{{AFX_VIRTUAL(CMainFrame)
    .......
    virtual void RecalcLayout(BOOL bNotify);
    //}}AFX_VIRTUAL  
 


And this to the CPP file:

CMainFrame::CMainFrame()
{
    mp_MainToolBar = 0;
    .......
}

void CMainFrame::RecalcLayout(BOOL bNotify)
{
    CXTPMDIFrameWnd::RecalcLayout(bNotify);

    if (mp_MainToolBar && mp_MainToolBar->GetSafeHwnd())
    {
        CRect k_Wnd;
        GetClientRect(&k_Wnd);
       
        CRect k_Bar;
        mp_MainToolBar->GetClientRect(&k_Bar);
        mp_MainToolBar->MoveWindow(0, 0, k_Wnd.Width()-2, k_Bar.Height());
        mp_MainToolBar->Invalidate(FALSE);
    }
}



3.)
Up to now I'm still searching without success how to remove ONLY the menu "Add or remove buttons"
WITHOUT removing the entire menu at the right side that appears when not all icons fit into the toolbar.







P.S.
I solved it partially, but after an entire day I still don't have what I wanted.

I hope that in the future there will be a tutorial available that is like mine here and explains how to do things like these!
This tutorial must explain the main features !with screenshots! - !NOT ONLY TEXT! and explain how to use this huge toolkit.

Elmü

Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 07 June 2010 at 2:41pm
You need something like this for MFC version (untested code)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
...
    ON_XTP_INITCOMMANDSPOPUP()
...
END_MESSAGE_MAP()
...
afx_msg void OnInitCommandsPopup(CXTPPopupBar* pComandBar);
...
void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{
    // get the list of commands for the popup.
    CXTPControls* pCommandList = pCommandBar->GetControls();

    // Remove "Add\Remove" menu item from the File menu.
    CXTPControl* pCommandNew = pCommandList->FindControl(
        xtpControlPopup, XTP_ID_CUSTOMIZE_ADDORREMOVE, TRUE, FALSE);
    if (pCommandNew)
    {
        pCommandList->Remove(pCommandNew);
    }
}

FYI, for #2 you just need xtpFlagStretched or xtpFlagStretchedShared
Back to Top
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Posted: 07 June 2010 at 11:59pm
Hello Mario

Thanks for you help.

In your code pCommandList->FindControl(..) returns 0.

Instead of
FindControl(xtpControlButton,.....
it must be
FindControl(xtpControlPopup,.....

This will successfully remove the menu entry "Add or remove buttons".

But the result is a little strange: An empty menu opens when all icons fit into the toolbar.



It would be better if nothing would open at all or even better:
if the little arrow button would not appear in the toolbar when all icons fit into the toolbar.

________________

Your second suggestion doesn't work:

I tried to set the flag xtpFlagStretched with
pMainToolBar->SetFlags(...)
and with
pMainToolBar->EnableDocking(...)
as described in the CommandReference.
Both have no effect.

Elmü


Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 08 June 2010 at 3:07pm
My solution assumed you did not want the expand button, so you would never see the blank popup.  So do you want this button or not?  Sounds like you need to hide the button for the toolbar and use my code, then it will have only not viewable buttons when popup appears.

So ShowExpandButton(FALSE) should be False, then use my code and you have what you were looking for. 

Add this line in Visual Studio GUI sample and you will see streched toolbar:

    CXTPToolBar* pThemeBar = (CXTPToolBar*)pCommandBars->Add(_T("Theme"), xtpBarTop);
    if (!pThemeBar ||
        !pThemeBar->LoadToolBar(IDR_TOOLBAR_THEME))
    {
        TRACE0("Failed to create toolbar\n");
        return -1;
    }

    pThemeBar->EnableDocking(xtpFlagStretchedShared); //<<<<<<<<<<<<<<<<<<<<<<<<< This line


Back to Top
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Posted: 08 June 2010 at 8:49pm
Hello Mario

Would it be possible that you try your code before posting here ?
Please *?*

>   pThemeBar->EnableDocking(xtpFlagStretchedShared);

This is EXACTLY what I did after your last posting.
And it defintiely does not change anything !

The toolbar stays the same size and does NOT fill 100% of the width of the window as my code does in RecalcLayout().

______________________

> So ShowExpandButton(FALSE) should be False, then use my code and you have what you were looking for.

This is one of the very first things that I tried and it does not do what you assume !

Look at this screenshot:



There are two symbols in the toolbar.
The upper one appears only if there are icons that don't fit into the toolbar, otherwise it disappears automatically.
The lower one is always there if ShowExpandButton(TRUE).

It would be perfect if I could turn them off separately and if I could define if I want to see "Add or remove buttons" in the menu.
But this is impossible.

ShowExpandButton(FALSE) turns them BOTH COMPLETELY off and FOR EVER!

This means even if there are icons that don't fit into the toolbar there will be no symbol visible at all that the user could click on.

So up to now I did not find how to do what I want.
I think this is a missing feature.

Why isn't there an option like this:

ShowExpandButton(xtpCommandButtonMoreIcons | xtpCommandButtonCustomizeMenu)

that would allow me to turn on and off individually what I want.

____________________________

Would you please try it before posting an answer ?
Thanks.

Elmü


Back to Top
lfoster View Drop Down
Groupie
Groupie


Joined: 26 April 2010
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote lfoster Quote  Post ReplyReply Direct Link To This Post Posted: 09 June 2010 at 9:04am
Thank you SuperMario and Elmu for this solution. I think there is some confusion still as to what we are trying to achieve. SuperMario's suggestion of setting ShowExpandButton(FALSE) just removes the whole button which is not what we want.

I have the drop down which correctly displays any buttons that do not fit on the toolbar. I still have the empty drop down though even when everything already fits on the toolbar.

Ideally the drop down would have nothing in it if everything could be squeezed onto the toolbar instead of the single blank entry but I can live with this.

Thanks again guys,

Lewis
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 09 June 2010 at 4:25pm
Trust me, the code works, it will make toolbar take up 100% of the remaining space available

pThemeBar->EnableDocking(xtpFlagStretchedShared);




Back to Top
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Posted: 10 June 2010 at 10:18am
Hello Mario

Thanks for the screenshot.
It shows me that we are talking about two different things.

You made the Themebar wider.
I am surprised that this functions.
I can reproduce your screenshot.

BUT:
The same code applied to the toolbar, that I am talking about, (the command bar) STILL does NOT work.

Modify your line
pThemeBar->EnableDocking(xtpFlagStretchedShared);
into
pCommandBar->EnableDocking(xtpFlagStretchedShared);
or
pCommandBar->EnableDocking(xtpFlagStretched);

And you will see that the upper bar stays unchanged !

I also tried SetFlags() which doesn't work either.

Why does the code work for one toolbar but not for another one ?
Strange!
Is this a bug ?

Elmü
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 11 June 2010 at 10:32am
my code works for all toolbars as seen below, maybe you load some old layout after setting this flag?  try to comment out any load settings\layout?
        //CXTPPropExchangeSection pxNormalLayout(px.GetSection(_T("NormalLayout")));
        //ExchangeLayout(&pxNormalLayout);

Back to Top
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Posted: 12 June 2010 at 12:02pm
Hello Mario

Yes you are right.
I deleted the file GUI_VisualStudio_vc60.xml.
And now the flag works.

When changing the code you must always delete this XML file or disable the code the loads the configuration otherwise any change at the code is ignored and the old configuration is loaded from the XML file.

But it makes a big difference if you use either my code in RecalcLayout or alternately the flag Stretched.
This difference becomes visible when you resize the window:




Elmü
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.