CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Question Dynamic Menu Bar Creation?

    Hello All,

    In my MDI project I have multiple Documents and Views. Based on the Document selected I want to change the Menu Bar. Is it possible to do this in the :
    Code:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
    		return -1;
    	
    	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) // Would like to change this to a
    different ToolBar????
    	{
    		TRACE0("Failed to create toolbar\n");
    		return -1;      // fail to create
    	}
    
    	if (!m_wndStatusBar.Create(this) ||
    		!m_wndStatusBar.SetIndicators(indicators,
    		  sizeof(indicators)/sizeof(UINT)))
    	{
    		TRACE0("Failed to create status bar\n");
    		return -1;      // fail to create
    	}
    
    	// TODO: Delete these three lines if you don't want the toolbar to
    	//  be dockable
    	//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    	//EnableDocking(CBRS_ALIGN_ANY);
    	//DockControlBar(&m_wndToolBar);
    
    	return 0;
    }
    or do I need to do it elsewhere? Any help would be greatly appreciated.

    Thanks!
    Charlie
    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Dynamic Menu Bar Creation?

    You could create the toolbars , hide them all in OnCreate and on activating a particular child frame window, show/hide the toolbars.

  3. #3
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Re: Dynamic Menu Bar Creation?

    Thanks for the quick response! Will give that a try... When you say create them all are you telling me to create then in the

    Code:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    function? Pretty sure you are, but would appreciate the clarification.

    Thanks Again,
    Charlie

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Dynamic Menu Bar Creation?

    OnCreate is the right place. BTW, did you say toolbar or menubar. Your code seems to be indicating a toolbar, while your question seems to be about menubar

  5. #5
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Re: Dynamic Menu Bar Creation?

    My apologies I did in fact mean ToolBar.

    Thanks!
    Charlie
    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Dynamic Menu Bar Creation?

    No. Problem.

  7. #7
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Re: Dynamic Menu Bar Creation?

    Again my apologies, but I am hoping you might be able to shed a little more light on this subject. I have created the ToolBars in the OnCreateClient in CMainFrame. You said I could show/hide them based on a particular CChildFrame being activated is this correct? My question is do I access the tool bar created in CMainFrame or do I need to create a new one in the CChildFrame? If you could provide a sample it would be Greatly appreciate?

    Thanks,
    Charlie
    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  8. #8
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Dynamic Menu Bar Creation?

    See attached. It contains a sample MDI app with 2 document templates. The 2 templates differ in the framewindow class. ChildFrm and ChildFrm2.

    1. ChildFrm when activated shall show toolbar1 and when deactivated shall hide toolbar1
    2. ChildFrm2 when activated shall show toolbar2 and when deactivated shall hide toolbar2

    Check out how WS_VISIBLE style is removed from the toolbar creation in mainfrm.cpp, and how ShowControlBar is used to show/hide individual toolbars in the same file
    Attached Files Attached Files

  9. #9
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Re: Dynamic Menu Bar Creation?

    Thank You! That is exactly what I was looking for. This will allow me to finally finish this project with all of the functionality I wanted! Thanks for taking the time and effort to provide a small project that will save me hours of frustration! Have a Great Day!

    Thanks,
    Charlie
    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured