Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Showing a toolbar.

Posted on 1999-06-25
Medium Priority
Last Modified: 2013-11-20
I created a toolbar within OnCreate in
mainframe.cpp.The toolbar is initially hidden.
I need to show the toolbar from within view.cpp
when a certain condition is true.
I have tried several approaches with no luck.

Question by:cMan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Accepted Solution

naveenkohli earned 400 total points
ID: 1307999
Here is sample code which will you idea on how to do it.
Create the tool bar in Frame class, set its styles, make it visible. Since you want to hide it intiallly, therefor before exiting the CMainFrame::OnCreate function hide the tool bar like this

ShowControlBar (&m_wndShapeToolBar, FALSE, FALSE);

And then in the view class, you can grab the frame to which this tool bar is attached. From the frame, get the pointer to the tool bar. And then call ShowToolBar. This sample function keeps flipping the visibility of tool bar. Like if its visible, then make it invisible or the other way round.
I was doing this test in my OnSetCursor function of my view class.

The way i have shown is just to give you idea. I am sure you can write a better efficient function.

BOOL CGridView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
      if (m_bOnXSection) {
            SetCursor (m_hIntersectionCursor);
            CWnd *pWnd = AfxGetMainWnd ();
            CFrameWnd *pFrame = static_cast<CFrameWnd *>(pWnd);
            CFrameWnd *pMainFrame = pFrame->GetActiveFrame ();
            CControlBar *pBar = pMainFrame->GetControlBar (ID_VIEW_SHAPE_TOOLBAR);
            if (pBar != NULL) {
                  bool isVisible = ((pBar->GetStyle () & WS_VISIBLE) != 0);
                  pMainFrame->ShowControlBar (pBar, !isVisible, FALSE);
            return TRUE;

      return CView::OnSetCursor(pWnd, nHitTest, message);

Author Comment

ID: 1308000
I didn't know about the ShowControlBar func.
That was what I needed.
m_bar.ShowWindow(SW_SHOW) wouldn't work!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question