• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Showing a toolbar.

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.

1 Solution
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);
cManAuthor Commented:
I didn't know about the ShowControlBar func.
That was what I needed.
m_bar.ShowWindow(SW_SHOW) wouldn't work!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now