How to change toolbar runtime

I  have  two toolbars  in my application.I  want  to change  toolbar  runtime. Inplace  of  first  toolbar  I  want  to  replace  second toolbar.
and vice versa  based  on  some  condition.How  to  do  it? Will  anyone  tell me  as  early as possible.
I  am  using  Visual C++ 2010 . And  my  toolbar  is CMFCToolbar.
ADITYA RAOSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help.

new MFC program with the wizard in VS-2010 you can choose this feature on the page "User Interface Features". Select "Use a menu bar and toolbar. There are two further settings "User-defined toolbars and images" and "Personal menu behavior". You have to select the first.

Look into the created code...


PS: Also the new BCG classes are completely compatible with MFC 2010
if you have an sdi or mdi mfc project you find the code for creating and loading the toolbar in mainfrm.h and mainfrm.cpp.

to be able to exchange the toolbar i would suggest to turn the member 'CMfcToolbar m_wndToolBar' to pointer member 'CMfcToolbar * m_pWndToolBar'.

in mainfrm.h do

class CMainFrame ...
    //CMfcToolbar m_wndToolBar;
    CMfcToolbar * m_pWndToolBar;
    CMfcToolbar * m_pWndToolBar1;
    CMfcToolbar * m_pWndToolBar2;

in mainfrm.cpp do:

CMainFrame::CMainCMfcToolbar m_wndToolBarFrame()
    : m_pWndToolBar(NULL), m_pWndToolBar1(NULL), m_pWndToolBar2(NULL)

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
        m_pWndToolBar = m_pWndToolBar1 = new CMfcToolBar();
		!m_pWndToolBar->LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
        m_pWndToolBar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);        

Open in new window

if done so far, the mainframe class now has a toolbar which could be exchanged by a second toolbar.

you would add a new function to CMainFrame which would hide the current toolbar 1 and create a second toolbar 2 by using the same functions as it was done for the first toolbar. store the pointer in m_pWndToolBar2 and visualize it by call ShowWindow. after that you should have two valid toolbars which you simply could switch by hiding the one and showing the other (you may need to add some additional code for docking and undocking the toolbar correctly).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ADITYA RAOSoftware DeveloperAuthor Commented:
Yes   Mr/Mrs  sarabande  it  finally  worked  out.Toolbar is changing
Thank  you  very  very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.