Print Page | Close Window

Manually changing main menu in an MDI app

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=2439
Printed Date: 13 May 2024 at 2:35am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Manually changing main menu in an MDI app
Posted By: JayW
Subject: Manually changing main menu in an MDI app
Date Posted: 23 June 2005 at 8:12am

I have an application with several MDI-based editor windows (similar in appearance to Visual Studio/Dreamweaver, etc.), but it also has docking panes containing tree controls and properties which are not doc/view windows. Using the CMultiDocTemplate template class, I faithfully registered each editor document type with its own resources (menus, accelerator tables, etc.) and menus change properly when you switch back and forth between different editor views as expected. However, I cannot seem to manually load menus when, for example, a pane containing a tree view of the document hierarchy gets focus. I tried the following code but strangely, when I look at it in the debugger, m_hMenuDefault is always NULL when entering the function, which obviously will not work (it's hard to destroy a menu that doesn't exist...)

void CMainFrame::SetMainMenu(UINT nIDResource)
{

    ASSERT(nIDResource);

    // Remove/destroy old menu
    SetMenu(NULL);
    ::DestroyMenu(m_hMenuDefault);

    // Add the requested menu
    m_defaultMenu.LoadMenu(nIDResource);
    ASSERT(m_defaultMenu);

    SetMenu(&m_defaultMenu);
    m_hMenuDefault = m_defaultMenu.m_hMenu;

}

Thanks in advance,

Jay




Replies:
Posted By: JayW
Date Posted: 23 June 2005 at 2:06pm

Well, I found a fix for MFC/Windows in general, but it isn't going to work with Command Bars.  I'm going to post a more honed request in a different thread so consider this one dead.

Jay



Posted By: Oleg
Date Posted: 04 July 2005 at 2:04am

try.

pCommandBars->GetMenuBar()->LoadMenu



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net